$optiondesc[1]="Change the URL to KC-Bike.net"; $optiondesc[2]="Use KC-Bike.net for advice and reviews, leave this site up for ride reports, rants, and humor"; $optiondesc[3]="Other way - Move all my ramblings to KC-Bike.net, leaving only advice and rich content here"; $optiondesc[4]="Don't care"; $pollno = 1; $DBHOST = "localhost"; $DBUSER = "kcbike"; $DBNAME = "kcbike"; $DBTABLE = "poll"; if($myDB = mysql_connect($DBHOST,$DBUSER)) { echo ""; } mysql_select_db($DBNAME,$myDB); $sql = "SELECT * FROM $DBTABLE where ipaddr='".$_SERVER['REMOTE_ADDR']."' and pollno='".$pollno."';"; if($result = mysql_query($sql,$myDB)){ if($row = mysql_fetch_array($result,MYSQL_BOTH)) { echo "you voted already."; poll_getopts($myDB,$optiondesc,$pollno); die; } } if (isset($_POST['complete'])){ if (isset($_POST['option'])){ $sql="INSERT INTO $DBTABLE (id,pollno,ipaddr,optsel,other) values (null,\"".$pollno."\",\"".$_SERVER['REMOTE_ADDR']."\",\"".$_POST['option']."\",NULL);"; mysql_query($sql,$myDB); echo 'Voted!'; poll_getopts($myDB,$optiondesc,$pollno); die; }else{ echo "You have to choose an option"; } } ?>
function poll_getopts($myDB,$optiondesc,$pollno){ $sql="select distinct optsel from poll where pollno='$pollno';"; $result2 = mysql_query($sql,$myDB); while($row = mysql_fetch_array($result2,MYSQL_BOTH)){ poll_dispopts($myDB,$optiondesc,$pollno,$row['optsel']); } } function poll_dispopts($myDB,$optiondesc,$pollno,$option){ // x of xx (xx%) $sql="select count(*) from poll where pollno='$pollno';"; $result3 = mysql_query($sql,$myDB); $baz=mysql_fetch_row($result3); $votes=$baz[0]; $sql="select count(*) from poll where pollno='$pollno' and optsel='$option';"; $result4 = mysql_query($sql,$myDB); $baz=mysql_fetch_row($result4); $thisoptct=$baz[0]; $pct=round(($thisoptct / $votes)*100, 1); echo "