1. Database creation
Table 1:diaoyantimu
Table 2:diaoyanxuanxiang
2. Page
Page 1: Poll Home
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title><styletype= "Text/css">#fanhui{Display:None}</style></Head><Body><formAction= "tpchuli.php"Method= "POST">
<?PHP$db=NewMysqli ("localhost", "root", "123", "MyDB");$sql= "SELECT * FROM Diaoyantimu";$result=$db->query ($sql);$attr=$result-Fetch_all ();foreach($attr as $v){ Echo"<div>{$v[1]} </div> "; $sxx= "SELECT * from Diaoyanxuanxiang where timudaihao= ' {$v[0]} ' "; $rxx=$db->query ($sxx); $axx=$rxx-Fetch_all (); $bs= 0; if(!Empty($_get["A"])) { $bs=$_get["A"]; } $s=$bs==1? " None ":" Block "; Echo"<div id= ' Toupiao ' style= ' display:{$s} ' > '; foreach($axx as $v 1) { Echo"<div><input type= ' checkbox ' name= ' tp[] ' value= ' {$v 1[0]} ' />{$v 1[1]} </div> "; } Echo"</div>"; $s 1=$bs==0? " None ":" Block "; //Show Poll Results Echo"<div id= ' Jieguo ' style= ' display:{$s 1} ' > '; foreach($axx as $v 2) { $v 2[2];//number of current options//Total number of persons $szrs= "Select sum (Numbers) from Diaoyanxuanxiang where timudaihao= ' {$v[0]} ' "; $rzrs=$db->query ($szrs); $azrs=$rzrs-Fetch_row (); $azrs[0];//Total number $BFB= ($v 2[2]/$azrs[0]) *100; Echo"<div>{$v 2[1]} <div style= ' width:100px; height:10px; border:1px solid black; ' ><div style= ' width:{$BFB}%; height:10px; Background-color:red ' ></div></div>{$v 2[2]} {$BFB}%</div> "; } Echo"</div>";}?>
<type= "Submit" value= "vote"/>
<inputtype= "button"ID= "JG"value= "View Results"onclick= "SHOWJG ()" /><inputtype= "button"ID= "Fanhui"value= "Back"onclick= "SHOWTP ()" /></form></Body><Scripttype= "Text/javascript">functionShowjg () {document.getElementById ("Jieguo"). Style.display="Block"; document.getElementById ("Toupiao"). Style.display="None"; document.getElementById ("JG"). Style.display="None"; document.getElementById ("Fanhui"). Style.display="Block"; }functionSHOWTP () {document.getElementById ("Jieguo"). Style.display="None"; document.getElementById ("Toupiao"). Style.display="Block"; document.getElementById ("JG"). Style.display="Block"; document.getElementById ("Fanhui"). Style.display="None";}</Script></HTML>
Page 2: Working with pages
<? PHP $attr $_post ["TP"]; $str implode ("', '",$attr); $sql = "Update Diaoyanxuanxiang set numbers = numbers+1 where IDs in (' {$str} ')"; $db New Mysqli ("localhost", "root", "123", "MyDB"); $db->query ($sql); Header ("Location:toupiao.php?a=1");
November 3 Morning PHP Exercise "poll"