?
Solved

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

Posted on 2003-03-29
4
Medium Priority
?
1,142 Views
Last Modified: 2013-12-12
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
Comment
Question by:denofdeath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 7

Accepted Solution

by:
Big_Red_Dog earned 1000 total points
ID: 8233312
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
 
LVL 1

Author Comment

by:denofdeath
ID: 8233371
Thanks for the quick reply...just one problem..
I get a parse error on line 14 which is the "while" statement.
Any ideas ??

0
 
LVL 1

Author Comment

by:denofdeath
ID: 8233392
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
 
LVL 1

Author Comment

by:denofdeath
ID: 8233398
Great quick answer considering my code was a little bad to start with.

Cheers

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question