本文实例为大家分享了PHP查询操作实现投票功能的代码,供大家参考,具体内容如下
题目:
解题方法汇总:
方法一:
1. 投票主页面:<form action="TouChuLi.PHP" method="post">
<?php
include ("DBDA.class.php");
$db=new DBDA();
//从调研题目表中找出题目代号和名称
$sql="select from diaoyantimu limit 0,1";
$arr=$db->query($sql);
$tmmc=$arr[0][1];
$tmdh=$arr[0][0];
echo "{$tmmc}:
//从调研选项表中输出选项内容:
$sqlxx="select from diaoyanxuanxiang where timudaihao='{$tmdh}'";
$arrxx=$db->query($sqlxx);
echo "
foreach ($arrxx as $v)
{
echo "
";
}
?>
<input type="submit" value="提交">
<input type="button" value="查看结果" id="check" onclick="Showjieguo()">
<div id="jieguo" style="display:none">
<?php
//计算总人数:
$sqlzs="select sum(numbers) from diaoyanxuanxiang where timudaihao='{$tmdh}'";
$zrs=$db->query($sqlzs);
foreach ($arrxx as $v)
{
$name=$v[1];
$number=$v[2];
if($zrs[0][0]==0)
{
$bfb = 0;
}
else
{
$bfb = ($number/$zrs[0][0])*100;
}
$bfb=round($bfb,2);
echo "
{$name}
"; } ?>