I am trying to create a json object in php that looks like this:
[{"month":"Jan","ABC":"79","DEF":"21","HIJ":"12"},
{"month":"Feb","ABC":"89","DEF":"35","HIJ":"8"}]
where ABC, DEF, HIJ
are providers of a service and the counts are how many products they delivered each month. I pull this data out of a MySQL database.
So far, I've only been able to produce this json object (which has value but I really need to prdice the other one too)
[{"month":"Jan",ABC":"79"},{"month":"Jan","DEF":"21"},{"month":"Jan","HIJ":"12"},{"month":"Feb","ABC":"89"},{"month":"Feb","DEF":"35"},{"month":"Feb","HIJ":"8"}]
using the php loop below:
while ($row = mysqli_fetch_assoc($result)) {
if ($row['Month'] == "01")
$new_array[] = array("month"=>"Jan", $row['provider']=>$row['count']);
if ($row['Month'] == "02")
$new_array[] = array( "month"=>"Feb",$row['provider']=>$row['count']);
and then I follow up with
**print json_encode($new_array);**
to view my output.
Thanks for helping me figure this out! happy New Year everyone.