码迷,mamicode.com
首页 > 其他好文 > 详细

投票联系题

时间:2016-11-06 09:31:34      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:选项   cal   check   sum   mysql   res   lock   select   from   

 1 <body>
 2 <form action="tpchuli.php" method="post">
 3 <?php
 4 
 5 $db = new  MySQLi("localhost","root","123","mydb");
 6 
 7 $sql = "select * from diaoyantimu";
 8 
 9 $result = $db->query($sql);
10 
11 $attr = $result->fetch_all();
12 
13 foreach($attr as $v)
14 {
15     echo "<div>{$v[1]}</div>";
16     
17     $sxx = "select * from diaoyanxuanxiang where timudaihao=‘{$v[0]}‘";
18     
19     $rxx = $db->query($sxx);    
20     $axx = $rxx->fetch_all();
21     
22     $bs = 0;
23     if(!empty($_GET["a"]))
24     {
25         $bs = $_GET["a"];
26     }
27     
28     $s = $bs==1?"none":"block";
29     
30     echo "<div id=‘toupiao‘ style=‘display:{$s}‘>";
31     foreach($axx as $v1)
32     {
33         echo "<div><input type=‘checkbox‘ name=‘tp[]‘ value=‘{$v1[0]}‘ />{$v1[1]}</div>";
34     }
35     echo "</div>";
36     
37     $s1 = $bs==0?"none":"block";
38     
39     //显示投票结果
40     echo "<div id=‘jieguo‘ style=‘display:{$s1}‘>";
41     
42     foreach($axx as $v2)
43     {
44         $v2[2]; //当前选项的人数
45         //求总人数
46         $szrs = "select sum(numbers) from diaoyanxuanxiang where timudaihao=‘{$v[0]}‘";
47         $rzrs = $db->query($szrs);
48         $azrs = $rzrs->fetch_row();
49         $azrs[0]; //总人数
50         
51         $bfb = ($v2[2]/$azrs[0])*100;
52         
53         echo "<div>{$v2[1]}<div style=‘width:100px; height:10px; border:1px solid black;‘><div style=‘width:{$bfb}%; height:10px; background-color:red‘></div></div>{$v2[2]} {$bfb}%</div>";
54     }
55     
56     echo "</div>";
57 }
58 
59 ?>
60 
61 <input type="submit" value="投票" />
62 <input type="button" id="jg" value="查看结果" onclick="showjg()" />
63 <input type="button" id="fanhui" value="返回" onclick="showtp()"  />
64 </form>
65 </body>
66 
67 <script type="text/javascript">
68 function showjg()
69 {
70     document.getElementById("jieguo").style.display="block";
71     document.getElementById("toupiao").style.display="none";
72     document.getElementById("jg").style.display="none";
73     document.getElementById("fanhui").style.display="block";
74     
75 }
76 
77 function showtp()
78 {
79     document.getElementById("jieguo").style.display="none";
80     document.getElementById("toupiao").style.display="block";
81     document.getElementById("jg").style.display="block";
82     document.getElementById("fanhui").style.display="none";
83 }
84 </script>
 1 <?php
 2 $attr = $_POST["tp"];
 3 
 4 $str = implode("‘,‘",$attr);
 5 
 6 $sql = "update diaoyanxuanxiang set numbers = numbers+1 where ids in(‘{$str}‘)";
 7 
 8 $db = new MySQLi("localhost","root","123","mydb");
 9 $db->query($sql);
10 
11 header("location:toupiao.php?a=1");

 

投票联系题

标签:选项   cal   check   sum   mysql   res   lock   select   from   

原文地址:http://www.cnblogs.com/The-second/p/6034723.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!