Main Page code:
<!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><style>. Liu{float: Left;}</style><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title></Head><Body><DivID= "Timu"style= "Display:block"><formAction= "tpcl.php"Method= "POST"><?phpinclude ("database.class.php"), $tm =new database (), $tm _result= $tm->query ("Select title from TM"); Echo $tm _ Result[0][0]. " <br> "; $tmxx _result= $tm->query (" SELECT * from Tmxx "), foreach ($tmxx _result as $v) {echo" <input type= ' checkb Ox ' value= ' {$v [0]} ' name= ' xx[] '/>{$v [1]}<br> ';}?><inputtype= "Submit"value= "vote" /> <inputtype= "button"value= "View Results"onclick= "Show ()"/></form></Div><DivID= "Jieguo"style= "Display:none"><?php$answer= $tm->query ("Select Options,numbers from Tmxx"), $sum = $tm->query ("Select sum (Numbers) from Tmxx where tmcode=1 "), foreach ($answer as $a) {$BFB =round ($a [1]/$sum [0][0]) *100,2); echo "<div><span class= ' Liu ' >{$a [0]} </span> <div class= ' Liu ' style= ' width:100 Px;height:10px;background-color: #CDCDCD ' > <div class= ' Liu ' style= ' width:{$bfb}%;height:10px;background -color:red ' ></div></div> <span>{$a [1]}</span> <span> ({$bfb}%) </span> </div> ";}?><Div><inputtype= "button"value= "Back"onclick= "Show1 ()" /></Div></Div></Body></HTML><Script>functionShow () {document.getElementById ("Timu"). Style.display="None"; document.getElementById ("Jieguo"). Style.display="Block";}functionShow1 () {document.getElementById ("Timu"). Style.display="Block"; document.getElementById ("Jieguo"). Style.display="None";}</Script>
Background processing code:
<?PHP$xx=$_post["XX"];include("database.class.php");$TPCL=Newdatabase ();if(!Empty($xx)){ foreach($xx as $v) { $TPCL _result=$TPCL->query ("Select numbers from Tmxx where code= ' {$v[0]} ' "); $TPCL _result=$TPCL _result[0] [0]+1; $TPCL _RESULT1=$TPCL->query ("Update tmxx set numbers=$TPCL _resultwhere Code= ' {$v[0]} ' ", 1); } Header("location:tp.php");}Else{ Header("location:error.php");}
Php-mysql Exercise: Simple voting