我有一个查询:
$result = mysql_query("SELECT
Left(Right(Base.inputs.Data_inf,4),3) As 'Datas',
count(Base.Data.Data_ID) As `U_Count`
FROM
Base.Data
WHERE
Base.Data_inputs.info = 'TREE'
GROUP BY ");
$rows = array();
while($r = mysql_fetch_array($result)) {
$row[0] = $r[0];
$row[1] = $r[1];
array_push($rows,$row);
}
print json_encode($rows, JSON_NUMERIC_CHECK);
结果是:
[["Data1",38],["Data2",13]]
我希望数据看起来更像:
[{"name":"Data1","data":[38]},{"name":"Data2","data":[13]}]
我试图使用这样的东西:
$rows = array();
while($r = mysql_fetch_array($sth)) {
$rows['name'] = $r['Datas'];
while($r = mysql_fetch_array($sth)) {
$rows['data'][] = $r['U_Count'];
}
}
但它不起作用。
任何人都可以帮忙吗?谢谢