Array Multidimensional from mysql result
I have the following problem I can not achieve the desired format of an array. I have:
while ($ row = mysql_fetch_assoc ($ result))
{
$ alias = $ row ['Alias'];
$ read = (int) $ row ['Read'];
$ data [$ alias] [] = $ read;
}
and I produce this array:
{"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]}
and I need this format:
[{"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]}]
This is my Query
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
Thank you all for the help
Something like this should get you there.
while ($row = mysql_fetch_assoc ($result))
{
$alias = $row['Alias'];
$read = (int) $row['Read'];
$data[] = array
(
'name' => $alias,
'data' => $read,
);
}
精彩评论