• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1164
  • Last Modified:

array from mysql to phplot only returning 1 row--help !!

After much fiddling I got the following to start working, but it only returns 1 row of data for the graph. How do I get the full recordset as an array that phplot will accept ?



<?php
//Include the code
include("../phplot.php");

//Define the object
$graph = new PHPlot;

//Set some data
$connect = mysql_connect('localhost', "someuser", "somepass");
 $sql=mysql_db_query(mydtatabase, 'select date, ph, solids from machinedata');
   $result =$sql
      or die(mysql_errno().": ".mysql_error()."<BR>".$sql);
     $result_array = mysql_fetch_array($result);
     
      $example_data = array($result_array);
      $graph->SetDataValues($example_data);


//Draw it
$graph->DrawGraph();

?>

0
denofdeath
Asked:
denofdeath
  • 3
1 Solution
 
Big_Red_DogCommented:
You need to loop through all of the results.  I also detected some other small errors.  Here is your code fixed up and looping:

<?php
//Include the code
include("../phplot.php");

//Define the object
$graph = new PHPlot;

//Set some data
$connect = mysql_connect('localhost', "someuser", "somepass");
$sql='select date, ph, solids from machinedata';
  $result =mysql_db_query(mydtatabase, $sql)
     or die(mysql_errno().": ".mysql_error()."<BR>".$sql);

while($result_array = mysql_fetch_array($result) {
     $example_data[] = array($result_array);
}

$graph->SetDataValues($example_data);


//Draw it
$graph->DrawGraph();

?>
0
 
denofdeathAuthor Commented:
Thanks for the quick reply...just one problem..
I get a parse error on line 14 which is the "while" statement.
Any ideas ??

0
 
denofdeathAuthor Commented:
Don't worry..I fixed the error !

while($result_array = mysql_fetch_array($result)) {
    $example_data[] = ($result_array);
}

Thanks, Saved me a heap of time :0)

0
 
denofdeathAuthor Commented:
Great quick answer considering my code was a little bad to start with.

Cheers

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now