三处理传过来的数据
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>无标题文档</title> 6 </head> 7 8 <body> 9 <!--接收用户传过来的的数据--> 10 <?php 11 include("./DBDA.class.php"); 12 $db = new dbda(); 13 $attr = $_POST["xx"]; 14 //var_dump($attr); 15 16 foreach($attr as $v) 17 { 18 $sql = "update diaoyanxuanxiang set numbers=numbers+1 where ids='{$v}'"; 19 $db->Query($sql,0); 20 } 21 //显示结果 22 $sql = "select * from diaoyanxuanxiang"; 23 $shuzu = $db->Query($sql); 24 25 $szs = "select sum(numbers) from diaoyanxuanxiang"; 26 $azs = $db->Query($szs); 27 $zs = $azs[0][0]; 28 29 foreach($shuzu as $v) 30 { 31 $bfb = ($v[2]/$zs)*100; 32 echo "{$v[1]}:{$v[2]}({$bfb}%)<div style='200px;height:10px; border:1px solid red;'><div style=' {$bfb}%; height:10px'></div></div>"; 33 } 34 35 36 37 ?> 38 39 </body> 40 </html>
二找出要投票的标题和题目名称
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>无标题文档</title> 6 </head> 7 8 <body> 9 <form action="jieguo.php" method="post"> 10 <?php 11 include("./DBDA.class.php"); 12 $db = new DBDA(); 13 14 $sql = "select * from diaoyantimu"; 15 16 $attr = $db->Query($sql,1);//成员方法里面类默认是1所以这里面要是查询的话1可以省掉不写。查询语句要返回二维数组$attr 17 18 echo "{$attr[0][1]}<br>";//这是输出题目的标题和题目的名称:晚上够干啥? 19 //根据题目的代号查出所有选项 20 $code = $attr[0][0]; 21 $sxx = "select * from diaoyanxuanxiang where timudaihao='{$code}'"; 22 23 $axx = $db->Query($sxx);//这个二位数组存着所有的选项信息 24 25 foreach($axx as $v) 26 { //echo "$v[1]<br>";//输出所有选项 27 //<input type='checkbox复选框 28 //value='{$v[0]}每个选项的代号 29 30 echo "<input type='checkbox' value='{$v[0]}' name='xx[]' />$v[1]<br>"; 31 } 32 33 ?> 34 35 <input type="submit" value="投票" /> 36 </form> 37 </body> 38 </html>