I created a bar graph for fast moving and slowmoving products. I already load the graph, but when I filter the graph by month, the the image will no longer show.
I think $_POST
method causes the error because when I put a static value to my query, the graph image will show.
Here is my code.
<?php include("phpgraphlib.php");
$graph=new PHPGraphLib(550,350);
include('myConnection.php');
$month = $_POST["month"];
$year = $_POST["year"];
$sql="SELECT menu_name, COUNT( * ) AS 'count'
FROM orders_menu AS om
INNER JOIN menu AS m ON m.menu_id_inc = om.menu_id_inc
WHERE MONTH(om.date_orderedmenu) = '$month'
AND YEAR(om.date_orderedmenu) = '$year'
GROUP BY menu_name";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
$dataArray=array();
if ($result) {
while ($row = mysql_fetch_assoc($result)) {
$menu=$row["menu_name"];
$count=$row["count"];
$dataArray[$menu]=$count;
arsort($dataArray);
array_slice($dataArray, 0,5);
}
}
$graph->addData($dataArray);
$graph->setDataValues(true);
$graph->setTitle("Fast Moving Dishes");
$graph->setGradient("green", "olive");
$graph->setBarOutlineColor("black");
$graph->createGraph();
?>