Mufleeh Posted July 11, 2011 Share Posted July 11, 2011 Hi, I have written below query which lists the information of Mathematics teachers for a given division. $query = $this->dbh->prepare("SELECT * FROM teachers_information WHERE nic IN (SELECT nic FROM teachers_current_school WHERE subject_name = 'Mathematics' AND school_id IN(SELECT school_id FROM schools WHERE division_id =(SELECT division_id FROM divisions WHERE division_name='$_POST[division_name]')))"); I displayed the results as below... foreach ($teachers AS $row) { echo "<tr>"; $i = $i + 1; echo "<td>$i.</td> <td>" .$row[division_id]."</td> <td>" .$row[nic]."</td> <td>" .$row[name_full]."</td> <td>". $row[date_of_birth]."</td> <td>". $row[sex]."</td> <td>". $row[address]."</td>"; } Now I need to plot a graph against the schools and the number of Math teachers. Here the schools can be indicated by school_id and also I believe the number of Math teachers can be taken from the row count. Below is a sample I got from the PHPlot manual which gives a basig graph and I am wondering how to replace the array with my queried results. Can anyone please help me to fix this? <?php //Include the code require_once 'phplot.php'; //Define the object $plot = new PHPlot(); //Define some data $example_data = array( array('a',3), array('b',5), array('c',7), array('d',, array('e',2), array('f',6), array('g',7) ); $plot->SetFontGD(x_label,5); $plot->SetFontGD(y_label,5); $plot->SetDataValues($example_data); //Turn off X axis ticks and labels because they get in the way: $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); //Draw it $plot->DrawGraph(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/241638-arranging-array-for-phplot/ Share on other sites More sharing options...
darkfreaks Posted July 11, 2011 Share Posted July 11, 2011 instead of the array do this $data=array(); while($row=mysql_fetch_assoc($result,MYSQL_ASSOC)) { $data[]=$row; } $plot->SetFontGD(x_label,5); $plot->SetFontGD(y_label,5); $plot->SetDataValues($data); //Turn off X axis ticks and labels because they get in the way: $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); //Draw it $plot->DrawGraph(); Quote Link to comment https://forums.phpfreaks.com/topic/241638-arranging-array-for-phplot/#findComment-1241112 Share on other sites More sharing options...
Mufleeh Posted July 11, 2011 Author Share Posted July 11, 2011 instead of the array do this $data=array(); while($row=mysql_fetch_assoc($result,MYSQL_ASSOC)) { $data[]=$row; } $plot->SetFontGD(x_label,5); $plot->SetFontGD(y_label,5); $plot->SetDataValues($data); //Turn off X axis ticks and labels because they get in the way: $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); //Draw it $plot->DrawGraph(); Hi, I am trying with it...will keep you updated Regards, Mufleeh Quote Link to comment https://forums.phpfreaks.com/topic/241638-arranging-array-for-phplot/#findComment-1241119 Share on other sites More sharing options...
Mufleeh Posted July 11, 2011 Author Share Posted July 11, 2011 Hi, As you see, my scripts are written using PDO objects. So can I make your script as below and also please tell me how to define the axis of the graph with required fields? $result = $dbh->query($query); $rows = $result->fetchAll(PDO::FETCH_ASSOC); $data=array(); while($rows=fetch($result)) { $data[]=$rows; } Quote Link to comment https://forums.phpfreaks.com/topic/241638-arranging-array-for-phplot/#findComment-1241127 Share on other sites More sharing options...
darkfreaks Posted July 11, 2011 Share Posted July 11, 2011 http://www.karakas-online.de/forum/viewtopic.php?t=10598 explains how to set X and Y Axis's Quote Link to comment https://forums.phpfreaks.com/topic/241638-arranging-array-for-phplot/#findComment-1241134 Share on other sites More sharing options...
Mufleeh Posted July 11, 2011 Author Share Posted July 11, 2011 Hi, Thanks its a great resource for me. Can you please correct the PHP that I have written using PDO as its not working? Regards, Mufleeh Quote Link to comment https://forums.phpfreaks.com/topic/241638-arranging-array-for-phplot/#findComment-1241141 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.