投票联系题

Posted 小学员G

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了投票联系题相关的知识,希望对你有一定的参考价值。

 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");

 

以上是关于投票联系题的主要内容,如果未能解决你的问题,请参考以下文章

如何使用片段将联系人选择到edittext

检索数据未出现在 ListView 的片段中

运用php做投票题,例题

我可以在 android studio 的片段上使用 Firebase 吗?

运用php做投票题,例题

运用php做投票题,例题