PHP Query Poll exercise (0508)

Source: Internet
Author: User

Practice Topics:

Solving:

Method One:

1. Poll Main Page:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

2. Processing the polling page:

<?php$arr=$_post["XX"];include (".. /dbda.class.php "), $db =new Dbda (), foreach ($arr as $v) {$sql =" Update Diaoyanxuanxiang set numbers = numbers+1 where ids = ' {$v} ' "; $db->query ($sql, 1);//1 represents $sql type}header (" location:TouPiao.php ");? >

3. Establish a class to access the database, encapsulated for reference:

<?php//executes an SQL statement that returns the corresponding result class dbda{public $host = "localhost";//database server address public $uid = "root";//database user name public $ Password= "";//Database Password//Execute SQL statement method//Parameter: $sql represents the SQL statement to execute; $type is the type of SQL statement, 0 for query, 1 for other (add-on); $db represents the database function to be manipulated Query ($sql, $type =0, $db = "MyDB") {//Build Connection Object $dbconnect=new mysqli ($this->host, $this->uid, $this->password, $db );//Determine if the connection is wrong!mysqli_connect_error () or Die ("Connection failed! ");//Execute SQL statement $result= $dbconnect->query ($sql);//Determine SQL statement type if ($type ==0) {//If the query statement returns a two-dimensional array of result sets return $result Fetch_all ();} else{//if it is a different statement, returns TRUE or Falsereturn $result;}}}

  Method Two:

1. Poll Main Page:

2. Processing the polling page:

<?php$arr=$_post["XX"];include (".. /dbda.class.php "), $db =new Dbda (), foreach ($arr as $v) {$sql =" Update Diaoyanxuanxiang set numbers = numbers+1 where ids = ' {$v} ' "; $db->query ($sql, 1);//1 represents $sql type}header (" location:TouPiao.php ");? >

3. View the poll results page:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

  

Page Display results:

 

PHP Query Poll exercise (0508)

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.