query("BEGIN; CREATE TABLE voteoptions (id INTEGER PRIMARY KEY, name CHAR(20)); INSERT INTO voteoptions (name) VALUES('hat'); INSERT INTO voteoptions (name) VALUES('mug'); INSERT INTO voteoptions (name) VALUES('shirt'); INSERT INTO voteoptions (name) VALUES('cup'); COMMIT;"); $db->query("BEGIN; CREATE TABLE poll (id INTEGER PRIMARY KEY, vote CHAR(20)); INSERT INTO poll (vote) VALUES('hat'); INSERT INTO poll (vote) VALUES('hat'); INSERT INTO poll (vote) VALUES('shirt'); INSERT INTO poll (vote) VALUES('mug'); INSERT INTO poll (vote) VALUES('hat'); INSERT INTO poll (vote) VALUES('hat'); COMMIT;"); */ //@ query $optionsquery = $db->query("SELECT * FROM voteoptions"); $numoptions = $optionsquery->numRows(); $pollquery = $db->query("SELECT * FROM poll"); $numvotes = $pollquery->numRows(); //@ setup display(s) $xval = 30; $barwidth = floor(300/$numoptions); for ($i=0;$i<=($numoptions-1);$i++) { $entry = $optionsquery->fetchAll(SQLITE_ASSOC); $voteoption = $entry[$i]['name']; $votevalue = $voteoption; //sqlite_result($optionsquery,$i,'name'); $currentnumquery = $db->query("SELECT * FROM poll WHERE vote='$votevalue'"); $currentnum = $currentnumquery->numRows(); $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); } //@ generate image(s) imagepng($im); // imagepng($im,'voting-plot.png'); // echo '
'; // echo ''; // echo '
'; ?>