dapcigar Posted May 19, 2014 Share Posted May 19, 2014 Am trying to query my DB and use the result to create a chart. code pasted below; <?php$date = $_POST['Date'];//$date = '25/05/2010';$date = str_replace('/', '-', $date);$new_date = date('Y-m-d', strtotime($date));//echo $new_date;include('mysql_connect.php');// Settings for the graphinclude "libchart/classes/libchart.php"; $chart = new VerticalBarChart(600, 520); $chart = new VerticalBarChart();$dataSet = new XYDataSet(); $query1 = mysql_query ("select * from requisition where date = '$new_date' ") or die(mysql_error()); while($row = mysql_fetch_array($query1)){ //$amt = $row['amount']; // check each department and sum up all their data if ( $row['department'] = "ICT") { $total1 = $total1 + $row['amount']; //exit; } else if ( $row['department'] = "Supply Chain/ Asset Integrity") { $total2 = $total2 + $row['amount']; //exit; } else if ( $row['department'] = "Account") { $total3 = $total3 + $row['amount']; //exit; } else if ( $row['department'] = "Admin / Services") { $total4 = $total4 + $row['amount']; //exit; } else if ( $row['department'] = "Business Development") { $total5 = $total5 + $row['amount']; //exit; } else if ( $row['department'] = "Manpower") { $total6 = $total6 + $row['amount']; //exit; } else if ( $row['department'] = "Maintenance") { $total7 = $total7 + $row['amount']; //exit; } else if ( $row['department'] = "HR") { $total8 = $total8 + $row['amount']; //exit; } else if ( $row['department'] = "Marine Logistics") { $total9 = $total9 + $row['amount']; //exit; }//$dataSet->addPoint(new Point($row['department'], $row['amount']));}$dataSet->addPoint(new Point("ICT", $total1));$dataSet->addPoint(new Point("Supply Chain", $total2));$dataSet->addPoint(new Point("Account", $total3));$dataSet->addPoint(new Point("Admin / Services", $total4));$dataSet->addPoint(new Point("Business Development", $total5));$dataSet->addPoint(new Point("Manpower", $total6));$dataSet->addPoint(new Point("Maintenance", $total7));$dataSet->addPoint(new Point("HR", $total8));$dataSet->addPoint(new Point("Logistics", $total9));$chart->setDataSet($dataSet);$chart->setTitle("Report By Date - $date"); $chart->render("generated/date.png"); header("Location: view_date.php"); //header ('lcoation : '); ?> ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: When i Try to view the result, it only displays the first one in the IF statement. please, what am i doing wrong? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/288600-chart-not-displaying-properly/ Share on other sites More sharing options...
cyberRobot Posted May 19, 2014 Share Posted May 19, 2014 You're using an assignment operator (=) instead of the comparison operator for equals (==). More information can be found here: http://www.php.net/manual/en/language.operators.comparison.php Quote Link to comment https://forums.phpfreaks.com/topic/288600-chart-not-displaying-properly/#findComment-1480055 Share on other sites More sharing options...
Solution Barand Posted May 19, 2014 Solution Share Posted May 19, 2014 Why don't you save yourself some coding and SELECT department , SUM(amount) as amt FROM requisition WHERE date = '$new_date' GROUP BY department Quote Link to comment https://forums.phpfreaks.com/topic/288600-chart-not-displaying-properly/#findComment-1480056 Share on other sites More sharing options...
dapcigar Posted May 19, 2014 Author Share Posted May 19, 2014 Phew!! that worked perfectly.. thanks Quote Link to comment https://forums.phpfreaks.com/topic/288600-chart-not-displaying-properly/#findComment-1480058 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.