主页面代码:
<!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="投票" /> <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]} </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> <span>{$a[1]}</span> <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"); }
时间: 2024-10-07 20:31:17