PHP Query Polling exercise (0508), php0508
Practice Topics:
Solving:
Method One:
1. Poll Main Page:
Vote
Query ($sql, 1);//1 represents the type of $sql}header ("location:TouPiao.php"); >
3. Establish a class to access the database, encapsulated for reference:
Host, $this->uid, $this->password, $db);//Determine connection error!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:
Vote
2. Processing the polling page:
Query ($sql, 1);//1 represents the type of $sql}header ("location:TouPiao.php"); >
3. View the poll results page:
View Results
Query ($sql); $tmmc = $arr [0][1];echo]{$TMMC}:
";//Export the option contents from the Research options table: $SQLXX =" SELECT * from Diaoyanxuanxiang where timudaihao= ' {$arr [0][0]} ' "; $arrxx = $db->query ($ SQLXX);//Calculate total number of people: $sqlzs = "Select sum (Numbers) from Diaoyanxuanxiang where timudaihao= ' {$arr [0][0]} '"; $zrs = $db Query ($sqlzs), foreach ($arrxx as $v) {$name = $v [1];//research project Name $number = $v [2];//Select the number of people//determine if the total number is 0 if ($zrs [0][0]==0) { $BFB = 0; } else { $BFB = ($number/$ZRS [0][0]) *100;//percent } $bfb =round ($BFB, 2);//two digits after decimal point echo "{$ Number} {$bfb}%
";}? >
Page Display results:
http://www.bkjia.com/PHPjc/1125074.html www.bkjia.com true http://www.bkjia.com/PHPjc/1125074.html techarticle PHP Query Polling exercise (0508), php0508 Practice topic: Problem Solving: Method One: 1. Poll Main Page:! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://w ...