PHP-MySQL练习:简单投票

主页面代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
.liu
{
    float:left;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<div id="timu" style="display:block">
<form action="tpcl.php" method="post">


<?php
include("database.class.php");
$tm=new database();
$tm_result=$tm->query("select title from tm");
echo $tm_result[0][0]."<br>";
$tmxx_result=$tm->Query("select * from tmxx");
foreach($tmxx_result as $v)
{
    echo "<input type='checkbox' value='{$v[0]}' name='xx[]'/>{$v[1]}<br>";
}
?>

<input type="submit" value="投票" />&nbsp;<input  type="button" value="查看结果" onclick="show()"/>



</form>
</div>

<div id="jieguo" style="display:none">
<?php
$answer=$tm->Query("select options,numbers from tmxx");
$sum=$tm->Query("select sum(numbers) from tmxx where tmcode=1");
foreach($answer as $a)
{
    $bfb=round(($a[1]/$sum[0][0])*100,2);
    echo "<div><span class='liu'>{$a[0]}&nbsp;</span>
               <div class='liu' style='width:100px;height:10px;background-color:#CDCDCD'>
               <div class='liu' style='width:{$bfb}%;height:10px;background-color:red'></div></div>&nbsp;
               <span>{$a[1]}</span>&nbsp;
               <span>({$bfb}%)</span>
         </div>";
}





?>
<div><input type="button" value="返回" onclick="show1()" /></div>
</div>
</body>
</html>
<script>
function show ()
{
    document.getElementById("timu").style.display="none";
    document.getElementById("jieguo").style.display="block";
}
function show1()
{
    document.getElementById("timu").style.display="block";
    document.getElementById("jieguo").style.display="none";
}

</script>

后台处理代码:

<?php

$xx=$_POST["xx"];
include("database.class.php");
$tpcl=new database();
if(!empty($xx))
{
    foreach($xx as $v)
    {
        $tpcl_result=$tpcl->Query("select numbers from tmxx where code='{$v[0]}'");
        $tpcl_result=$tpcl_result[0][0]+1;
        $tpcl_result1=$tpcl->Query("update tmxx set numbers=$tpcl_result where code='{$v[0]}'",1);
    }
    header("location:tp.php");
}
else
{
    header("location:error.php");
}

 

转载于:https://www.cnblogs.com/Itwonderful/p/5470521.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值