Case: Voting

Source: Internet
Author: User

If you do not learn, can only show that you do not work hard, only this.

Package Class Dbda page:

<?PHPHeader("Content-type:text/html;charset=utf-8");classdbda{ Public $host= "localhost";  Public $uid= "Root";  Public $pwd= "123";  Public $dbconnect; functionQuery$sql,$type=1,$dbname= "Diaocha")    {        $this->dbconnect=NewMysqli ($this->host,$this->uid,$this->pwd,$dbname); if(!Mysqli_connect_error())        {            $result=$this->dbconnect->query ($sql); if($type==1)            {                return $result-Fetch_all (); }            Else            {                return $result; }        }        Else         {            Echo"Connection Failed"; }    }}

Main Page:

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >PHPinclude"Dbda. CLASS. PHP ";$timu=NewDbda ();$sql= "Select title from Diaoyantimu where Ids=1";$a=$timu->query ($sql);foreach($a  as $v){    Echo"{$v[0]} ";}? ><form action= "result1.php" method= "post" &GT;&LT;?PHP$DX=NewDbda ();$sql= "SELECT * from Diaoyanxuanxiang where timudaihao=1";$b=$DX->query ($sql);foreach($b  as $n){    Echo"<input type= ' checkbox ' name= ' check[] ' value= ' {$n[0]} ' />{$n[1]} <br/> ";}><input type= "Submit" value= "commit"/><a href= "result.php" ><input type= "button" value= "View results"/> </a></form></div></body>

Click the View Results button (Butturn) effect page:

<body><?PHPinclude"DBDA.class.php";$xx=NewDbda ();//Output Topics$s= "SELECT * from Diaoyantimu where Ids=1";$shuzu=$xx->query ($s);Echo $shuzu[0] [1];//Output Options$sql= "SELECT * from Diaoyanxuanxiang where timudaihao=1";$attr=$xx->query ($sql);$sq= "Select sum (Numbers) from Diaoyanxuanxiang where timudaihao=1";$at=$xx->query ($sq);$total=$at[0] [0];foreach($attr  as $v){        $d=($v[2]/$total) *100; Echo"<div> <span style= ' float:left; ' >{$v[1]}&nbsp;</span> <div style= ' width:100px; height:15px; border:1px solid #000000; Float:left ' > <div style= ' width:{$d}%;height:15px; background-color:red; '    > </div> </div>; <span style= ' Float:left ' >&nbsp; {$v[2]}</span> <span style= ' Float:left ' >&nbsp; {$d}%</span> </div>"; }><a href= "prctice.php" ><input style= "Cursor:pointer" type= "button" value= "return"/></a></ Body>

Submit Processing page:

<?PHP//Submitinclude"DBDA.class.php";$DX=NewDbda ();if(!Empty($_post)){$v 1=$_post["Check"];//gets to the arrayVar_dump($v 1);foreach($v 1  as $v 2){    $s= "Update Diaoyanxuanxiang set numbers=numbers+1 where ids={$v 2}"; Var_dump($s); $DX->query ($s, 2); //Var_dump ($dx->query ($s, 0));}}Header("location:result.php");

Case: 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.