我有以下问题,我无法实现所需的数组格式。我:
while ($ row = mysql_fetch_assoc ($ result))
{
$ alias = $ row ['Alias'];
$ read = (int) $ row ['Read'];
$ data [$ alias] [] = $ read;
}
,我生成了这个数组:
{"310-Amb":[23,24,24,25],
"310-Nev1":[5,5],
"310-Nev2":[6,6],
"310-Nev3":[5,5,4,4,5,4,5,5,5,4,4,5,5]}
,我需要这个格式:
[{"name":"310-Amb","data":[23,24,24,25]},
{"name":"310-Nev1","data":[-74]},
{"name":"310-Nev2","data":[5]},
{"name":"310-Nev3","data":[5,6,6,5,5,4,4,5,4,5,5,5]}]
这是我的查询
SELECT read.Id, read.Fecha, read.Hora, productos.Producto, neveras.Alias, neveras.Min,
neveras.Max, read.Lectura FROM read Inner Join neveras ON read.Nevera_Id = neveras.Id
Inner Join productos ON neveras.Producto = productos.Id WHERE Hora between
SUBTIME(CURTIME() , '03:00:00') And CURTIME() And read.$TipoClienteX = $IdX
ORDER BY Alias, Hora Asc
谢谢大家的帮助
像这样的东西应该会让你到达那里。
while ($row = mysql_fetch_assoc ($result))
{
$alias = $row['Alias'];
$read = (int) $row['Read'];
$data[] = array
(
'name' => $alias,
'data' => $read,
);
}