Hi all.
I have tried a post in the DATABASE forum but I did not help that solved my problem.
I am trying to extract data from a table into an array to use for producing graphs (bar chart). the code I am working with is below.
I have a table named "bag". the table has 2 fields, f_date and f_bag.
f_date (DATE TYPE)
f_bag (INT)
How can I count the total of "f_bag" for each month, where f_date holds dates. If I manually provide data for the array the graph is produced, but trying to extract data from my table is not so good.
$company = $_SESSION['_user']['company_name'] ;
require_once('../../Connections/con.php');
include ("/jpGraph/jpgraph.php");
include ("jpGraph/jpgraph_bar.php");
include ("jpGraph/jpgraph_date.php");
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_bag, $bag);
$query_found = "SELECT * FROM bag";
$found = mysql_query($query_found, $bag) or die(mysql_error());
$row_found = mysql_fetch_assoc($found);
$totalRows_found = mysql_num_rows($found);
// Some data I have written manually which I want to be replaced with data from my table.
$databary=array(1122,1700,2245,6009,0,0,0,0);
//$databary=array($totalRows_found);
$months=$gDateLocale->GetShortMonth();
// New graph with a drop shadow
$graph = new Graph(600,200,'auto');
$graph->SetShadow();
// Use a "text" X-scale
$graph->SetScale("datlin");
$graph->SetTickDensity(TICKD_DENSE);
$graph->yscale->SetAutoTicks();
// Specify X-labels
$graph->xaxis->SetTickLabels($months);
;
// Set title and subtitle
$graph->title->Set($company);
// Use built in font
$graph->title->SetFont(FF_FONT1,FS_BOLD);
// Create the bar plot
$b1 = new BarPlot($databary);
$b1->SetLegend("Baggage");
$b1->SetAbsWidth(10);
$b1->SetShadow();
// The order the plots are added determines who's ontop
$graph->Add($b1);
// Finally output the image
$graph->Stroke();
Can anyone help please.