JPGraph mysql_fetch_array
Posted: Fri Mar 12, 2010 11:42 pm
I don't have a specific question, this is just for the search engine since I had difficulty locating an answer to my question and I want to post something specific for anyone else.
If you're using JPGraph and can't quite figure out why my_sql_fetch_array() doesn't work in place of array(), here's your solution.
The short version is that you have to read the data returned by my_sql_fetch_array() in to a new array().
Note that the above code is only that which related to populating the arrays for the graph and the legend. Adapt as necessary.
If you're using JPGraph and can't quite figure out why my_sql_fetch_array() doesn't work in place of array(), here's your solution.
The short version is that you have to read the data returned by my_sql_fetch_array() in to a new array().
Code: Select all
<?php
$sql = mysql_query(SELECT * from table);
While ($row = mysql_fetch_array($sql)) {
global $data, $label; //if you don't declare these globals, the new arrays will not be usable outside of this loop
$data[] = $row['balance'];
$label[] = $row['creditor_name'];
}
$graph = new PieGraph(400,400);
$p1->SetLegends($label);
?>