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)