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

Link to comment
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();

 

 

Hi,

 

I am trying with it...will keep you updated

 

Regards,

Mufleeh

Link to comment
Share on other sites

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;

}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.