: Php query voting exercise (0508): exercise question: Problem solving: Method 1: 1. voting Home Page: & lt; metahtt exercise question:
Solution:
Method 1:
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:
The above introduces the php voting query exercise (0508), including php and exercises, and hopes to help those who are interested in PHP tutorials.