sql -- tutorial(s)
//header ("Content-type: image/png");
$im = imagecreatefrompng ("@walk.png");
$red = imagecolorallocate ($im, 255, 0, 0);
$black = imagecolorallocate ($im, 0, 0, 0);
mysql_connect("localhost", "root", "hush");
mysql_query("USE local");
$optionsquery = mysql_query("SELECT * FROM voteoptions");
$numoptions = mysql_num_rows($optionsquery);
$pollquery = mysql_query("SELECT * FROM votes");
$numvotes = mysql_num_rows($pollquery);
$xval = 30;
$barwidth = floor(300/$numoptions);
for ($i=0;$i<=($numoptions-1);$i++)
{
$voteoption = mysql_result($optionsquery,$i,'name');
$votevalue = mysql_result($optionsquery,$i,'value');
// echo $voteoption.' '.$votevalue.'
';
$currentnumquery = mysql_query("SELECT * FROM votes WHERE vote='$votevalue'");
$currentnum = mysql_num_rows($currentnumquery);
$per = floor(($currentnum/$numvotes)*184);
$rper = floor(($currentnum/$numvotes)*100);
imagefilledrectangle ($im, $xval, (200-$per), ($xval+$barwidth), 200, $red);
imagerectangle ($im, $xval, (200-$per), ($xval+$barwidth), 200, $black);
imagestring ($im, 1, ($xval+($barwidth/2)), 205, $voteoption, $black);
imagestring ($im, 2, ($xval+($barwidth/2)), ((200-$per)-15), "$rper%", $black);
$xval+=($barwidth+10);
}
imagepng($im,'voting-plot.png');
?>