Hi,
I have the following:
$sql = mysql_query("SELECT clicks FROM _________");
while($row = mysql_fetch_array($sql))
{
$newarray[] = $row['clicks'];
}
$graph=new PHPGraphLib(500,350);
$data=array($newarray,2002,432);
$graph->addData($data);
$graph->setTitle("Widgets Produced");
$graph->setGradient("red", "maroon");
$graph->createGraph();
I want to put the mysql returned click values into an array for the graph to show the amount of clicks on each day. So I want the $data=array() part to be like $data=array(302,323,3255,22,43,234), etc. but using my mysql rows data. So far the chart is only bringing up 2002 and 432, but that’s only because I have them written in that array.
I believe I need to do something so it remembers all the values outputting in the loop and then I can put then in the array function part with the comma, but not sure how.
Please help, thanks!
It wants an array of numbers, but you passed it an array whose first element is another array, second element is a number and third element is a number.
$sql = mysql_query("SELECT clicks FROM _________");
while($row = mysql_fetch_array($sql))
{
$newarray[] = $row['clicks'];
}
$newarray[] = 2002;
$newarray[] = 432;
$graph=new PHPGraphLib(500,350);
$graph->addData($newarray);
$graph->setTitle("Widgets Produced");
$graph->setGradient("red", "maroon");
$graph->createGraph();
If you didn’t mean to hard code 2002 and 432 as data points and want to only use the click counts from the database, then delete those two lines.
Thanks that wrks great. I’ve done a lot of php coding in the past, but took a back seater for 2 yrs and now a bit rusty.
I’ve got a new problem. I now need the $graph->addData($newarray); info changed.
So instead of the old $data=array(302,323,3255,22,43,234); I need it as follows.
$data=array(“03.01”=>145, “12.01”=>102, “19.01”=>123);
The 03.01 part is the date from the mysql database results and the 145 is the clicks data.
I so far have
$sqled = mysql_query("SELECT date, clicks FROM ________ limit 62");
while($rowed = mysql_fetch_array($sqled)){
$dated = $rowed['date'];
$dated = strtotime($dated);
$dated = date("d.m", $dated);
$newarray[] = "\\"$dated\\"=>$rowed[clicks],";
}
include("phpgraphlib.php");
$graph=new PHPGraphLib(600,350);
$graph->addData($newarray);
$graph->setTitle("Statistics");
$graph->setGradient("red", "maroon");
$graph->setDataValues(true);
$graph->createGraph();
But doesn’t seem to wrk. I’ll be there once I get that array correct for the graph. Once I’ve done that I should be fine from here on when it comes to the graph.
$newarray[$dated] = $rowed[‘clicks’];
Just had a little modification and your $newarray[$dated] = $rowed[‘click’]; actually worked.
This is the modification:
$clicks = $rowed[“clicks”];
$dataArray[$dated]=$clicks;
Thanks for your great help.