Php query voting exercise (0508), php0508_PHP tutorial

Source: Internet
Author: User
Php query voting exercise (0508), php0508. Php query voting exercises (0508), php0508 exercise questions: Problem solving: Method 1: 1. voting homepage :! DOCTYPEhtmlPUBLIC-W3CDTDXHTML1.0TransitionalENw php query voting exercise (0508), php0508

Exercise questions:

Solution:

Method 1:

1. voting homepage:

 Vote

Query ($ SQL, 1); // 1 indicates the $ SQL type} header ("location: TouPiao. php");?>

3. create a database access class and encapsulate it for reference:

 Host, $ this-> uid, $ this-> password, $ db); // You can check whether a connection error occurs! Mysqli_connect_error () or die ("connection failed! "); // Execute the SQL statement $ result = $ dbconnect-> query ($ SQL); // Determine the SQL statement type if ($ type = 0) {// if it is a two-dimensional array return $ result-> fetch_all ();} else {// if it is another statement, returns true or falsereturn $ result ;}}}

  Method 2:

1. voting homepage:

 Vote

2. process the voting page:

 Query ($ SQL, 1); // 1 indicates the $ SQL type} header ("location: TouPiao. php");?>

3. view the voting result page:

 View Results
 Query ($ SQL); $ tmmc = $ arr [0] [1]; echo"

{$ Tmmc }:

"; // Output option content from the survey option table: $ sqlxx =" select * from diaoyanxuanxiang where timudaihao = '{$ arr [0] [0]}' "; $ arrxx = $ db-> query ($ sqlxx); // calculates the total number of users: $ sqlzs = "select sum (numbers) from diaoyanxuanxiang where timudaihao = '{$ arr [0] [0]}' "; $ zrs = $ db-> query ($ sqlzs); foreach ($ arrxx as $ v) {$ name = $ v [1]; // survey project name $ number = $ v [2]; // select the number of people for this item // Determine whether the total number is 0 if ($ zrs [0] [0] = 0) {$ bfb = 0 ;} else {$ bfb = ($ number/$ zrs [0] [0]) * 100; // calculates the percentage} $ bfb = round ($ bfb, 2 ); // Two digits after the decimal point echo"

{$ Name}

{$ Number} {$ bfb} %


";}?>

  

Webpage display result:

 

Http://www.bkjia.com/PHPjc/1125074.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1125074.htmlTechArticlephp of the query voting exercises (0508), php0508 exercise questions: Problem solving: Method 1: 1. voting Home Page :! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http: // w...

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.