I am relatively knew to php and am trying to use it to analyse data from a db and create dynamic graphs.
As an example, I have a simple table
ID Area Search
1 North East Hair
2 North East Music
3 North West Food
4 North West Music
I have been playing with jpgraph and can create a graph which is driven from a query, something like: "SELECT Area, COUNT(*) as CountUp FROM php.`data` group by Area"
What I want is to drive this PHP function from an HTML form, so that the user can change selecy AREA, SEARCH, etc and the SQL is updated and refreshses the graph.
I'm a bit stuck on where to start with this?
My code at the moment is:
As an example, I have a simple table
ID Area Search
1 North East Hair
2 North East Music
3 North West Food
4 North West Music
I have been playing with jpgraph and can create a graph which is driven from a query, something like: "SELECT Area, COUNT(*) as CountUp FROM php.`data` group by Area"
What I want is to drive this PHP function from an HTML form, so that the user can change selecy AREA, SEARCH, etc and the SQL is updated and refreshses the graph.
I'm a bit stuck on where to start with this?
My code at the moment is:
Code:
<?php
include ("jpgraph.php");
include ("jpgraph_pie.php");
$host = 'localhost';
$user = 'root';
$bdd = 'PHP';
$password = '*****';
mysql_connect($host, $user,$password) or die("error connecting to server");
mysql_select_db($bdd) or die("error connecting to database");
$SQL = "SELECT Area, COUNT(*) as CountUp FROM php.`data` group by Area";
$RESULT = mysql_query($SQL);
if ($myrow=mysql_fetch_array($RESULT)) {
do {
$data[] = $myrow["CountUp"]; //It would not create the graphs without using '[]'
$data_names[] = $myrow["SHORT_DESC"].$myrow["Area"];
}while ($myrow=mysql_fetch_array($RESULT));
}
// Create the Pie Graph.
$graph = new PieGraph(520,400,$filename,60);
$graph->SetShadow();
// Set A title for the plot
// $graph->title->Set($PIE_TITLE);
$graph->title->Set ("Area Split");
$graph->title->SetFont(FF_VERDANA,FS_BOLD);
// Create
$p1 = new PiePlot($data);
$p1->SetCenter(0.35,0.5);
$p1->SetLegends($data_names);
$p1->SetTheme("earth");
$graph->Add($p1);
$graph->Stroke();
?>