PHP Voting exercises

Source: Internet
Author: User

First, the topic Requirements: the establishment of the following two databases, to achieve the statistical results of voting and%:

Ii. Specific methods of preparation:

(1), establish the database:

The table name of the blue background inside is the table we need!

The table reads as follows:

Table Name: Diaoyantimu

Table Name: Diaoyanxuanxiang

(2), encapsulation class file:

<?PHPclassdbda{ Public $fuwuqi= "localhost";  Public $yonghuming= "Root";  Public $mima= "Root";  Public $dbconnect; functionQuery ($sql,$type=1,$shujukuming= "Test")    {               $this->dbconnect =NewMysqli ($this->fuwuqi,$this->yonghuming,$this->mima,$shujukuming); if(!Mysqli_connect_error())        {                       $result=$this->dbconnect->query ($sql); if($type==1)            {                             return $result-Fetch_all (); }            Else            {                               return $result; }                }        Else        {            return"Connection Failed"; }                    }    }?>

(3), voting page (shouye.php):

<!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">. x{float: Left;}#top{width:500px;Height:200px;}#bottom{width:500px;Height:200px;Display:None;}#fanhui{Display:None;}</style></Head><Body><formAction= "chuli.php"Method= "POST"><?phpinclude ("DBDA.class.php"); $db =new dbda; $stm = "select * from Diaoyantimu limit 0,1"; $atm = $db->query ($stm); echo "<div> title: {$atm [0][1]}</div>"; $sxx = "SELECT * from Diaoyanxuanxiang where timudaihao= ' {$ATM [0][0]} ' "; $axx = $db->query ($sxx); echo" <div id= ' top ' > "; foreach ($axx as $v) {echo <div><input type= ' checkbox    ' value= ' {$v [0]} ' name= ' xx[] '/>{$v [1]}</div> '; }echo "</div>";?><DivID= "Bottom"><?php$sum= "Select sum (Numbers) from Diaoyanxuanxiang where timudaihao= ' {$ATM [0][0]} '"; $asum = $db->query ($sum); $      Total= $asum [0][0];foreach ($axx as $v) {$BFB = ($v [2]/$total) *100; echo "<div><span class= ' x ' >{$v [1]}</span> <div class= ' x ' style= ' border:1px solid blue;width : 120px; height:12px ' > <div style= ' background-color:red;height:12px;width:{$bfb}% ' ></div> </div> <s Pan class= ' x ' >&nbsp; {$v [2]}&nbsp;</span> <span class= ' x ' >{$bfb}%</span> </div> <div style= ' Clear:both ' & Gt;</div> ";}?></Div> <DivID= "Anniu"><inputtype= "Submit"value= "Submit"/><inputtype= "button"value= "View"onclick= "Showresult ()"/></Div><DivID= "Fanhui"><inputtype= "button"value= "Back"onclick= "Show ()" /></Div></form></Body><Scripttype= "Text/javascript">functionShowresult () {document.getElementById ("Top"). Style.display="None"; document.getElementById ("Bottom"). Style.display="Block"; document.getElementById ("Fanhui"). Style.display="Block"; document.getElementById ("Anniu"). Style.display="None";}functionShow () {document.getElementById ("Top"). Style.display="Block"; document.getElementById ("Bottom"). Style.display="None"; document.getElementById ("Fanhui"). Style.display="None"; document.getElementById ("Anniu"). Style.display="Block";}</Script></HTML>

(4), Voting processing page (chuli.php):

<? php$ids = $_post["xx"];include ("DBDA.class.php"), $db = new Dbda (), foreach ($ids as $v) {    $sql = "Update Diaoyanxuanxiang Set Numbers = numbers+1 where ids= ' {$v} ' ";    $db->query ($sql, 0);} Header ("location:shouye.php");

The results appear as follows:

PHP Voting exercises

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.