topical media & game development

talk show tell print

server-php-sqlite-voting-sql.php / php



  <?php
  //header ("Content-type: image/png");
  im = imagecreatefrompng ("@walk.png");
  red = imagecolorallocate (im, 255, 0, 0);
  black = imagecolorallocate (im, 0, 0, 0);
  

connect(s) / query (votes)


  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);
  

setup display(s)


  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.'<br />';
      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);
  }
  

create(s) image


  imagepng(im,'voting-plot.png');
  ?>
  <center>
  <img src=voting-plot.png width=100% height=100%>
  </center>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.