I have am using MySQL to generate data for a graph. The graph needs to include the months that have past during the current year. For Example: Today is July so the graph should include January-July. The SQL data does not have numbers for each month.
Here is my SQL Output:
Units_Counted Date
607 2
2120 5
42 7
The "date" field is the month.
When I print it to the graph I need it to look like this.
Units_Counted Date
0 1
607 2
0 3
0 4
2120 5
0 6
42 7
Here is my current PHP code. I need to add another loop in here but I cant seem to get it right.
$Month = 1;
foreach ($stmtIndividualGraphDatarows as $stmtIndividualGraphDatarow){
if ($stmtIndividualGraphDatarow['GraphMonth'] == $Month)
{
echo "{";
echo "'x': '".$stmtIndividualGraphDatarow['GraphMonth']."',";
echo "'y':".$stmtIndividualGraphDatarow['GraphCounts'];
echo "},";
}
else {
echo "{";
echo "'x': '".$Month."',";
echo "'y': 0";
echo "},";}
$Month++;
}