I'm dealing with highcharts with dynamic data (values retrieved from database).
By writing a query i was able to retrieve the following data from the table
Item 2011 2012
pen 5 7
pencil 4 20
eraser 6 43
I want to store the above info in the following structure and pass it to another page
[{ name:'pen', data: [5,7]},{ name:'pencil', data: [4,20]},{ name:'eraser', data: [6,43]}]";
I want to push the above data to the drilldown highchart.
Is there a way i can generate in this format? I've tried using json_encode but unable to succeed.
Can i achieve this using json_encode?
Updated
I've tried in this way
while($row = mysql_fetch_assoc($result))
{
$rows[]= $row;
}
echo json_encode($rows);
and got
[{"Item":"pen","2011":"5","2012":"7"},{"Item":"pencil","2011":"4","2012":"20"},{"Item":"eraser","2011":"6","2012":"43"}]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…