I wanted to be able to hand a simple database query to a function and have it graph it
without me going to a bunch of work, so I whipped up this little function. It takes
a database result and a title. The database result should be from a simple
query like “select group, count(*) from table group by group”. Just two columns, with
the first column being the labels, and the second column being numbers.
without me going to a bunch of work, so I whipped up this little function. It takes
a database result and a title. The database result should be from a simple
query like “select group, count(*) from table group by group”. Just two columns, with
the first column being the labels, and the second column being numbers.
<?php
include("class-graphs.php3");
Function
GraphResult($result,$title) {
/*
Takes a database result set.
The first column should be the name,
and the second column should be the values
*/
/*
db_ should be replaced with your database, aka mysql_ or pg_
*/
$rows=db_NumRows($result);
if ((!
$result) || ($rows < 1)) {
echo "None Found.n";
} else {
$names[];
$values[];
for (
$j=0; $j < db_NumRows($result); $j++) {
if (db_result($result, $j, 0) != "" && db_result($result, $j, 1) != "" ) {
$names[$j]= db_result($result, $j, 0);
$values[$j]= db_result($result, $j, 1);
}
}
/*
This is another function detailed below
*/
GraphIt($names,$values,$title);
}
}
?>