php查询操作实现投票功能(2)

<?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代表$sql的类型 } header ("location:TouPiao.php"); ?>

3. 查看投票结果页面:

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>查看结果</title> <style> .x { float:left;} </style> </head> <body> <?php include ("../DBDA.class.php"); $db=new DBDA(); //从调研题目表中找出题目代号和名称 $sql="select * from diaoyantimu limit 0,1"; $arr=$db->query($sql); $tmmc=$arr[0][1]; echo "<div><h2>{$tmmc}:</h2></div>"; //从调研选项表中输出选项内容: $sqlxx="select * from diaoyanxuanxiang where timudaihao='{$arr[0][0]}'"; $arrxx=$db->query($sqlxx); //计算总人数: $sqlzs="select sum(numbers) from diaoyanxuanxiang where timudaihao='{$arr[0][0]}'"; $zrs=$db->query($sqlzs); foreach ($arrxx as $v) { $name=$v[1];//调研项目名称 $number=$v[2];//选择该项的人数 //判断总人数是否为0 if($zrs[0][0]==0) { $bfb = 0; } else { $bfb = ($number/$zrs[0][0])*100;//求百分比 } $bfb=round($bfb,2); //取小数点后两位 echo "<div> <span>{$name} </span> <div> <div> </div> </div> <span>{$number} </span> <span>{$bfb}%</span><br /> </div><br />"; } ?> <br /> <a href="https://www.jb51.net/TouPiao.php"><input type="button" value="返回"></a> </body> </html>

显示结果:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/77404a1eb88ad8c430bc64798019ddf7.html