Jump to content

Arranging array for PHPlot


Mufleeh

Recommended Posts

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',8),

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();

 

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/241638-arranging-array-for-phplot/
Share on other sites

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();

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

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;

}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.