Php-mysql Exercise: Simple voting

Source: Internet
Author: User

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" />&nbsp;<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]}&nbsp;</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>&nbsp;               <span>{$a [1]}</span>&nbsp; <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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.