首页 > 代码库 > 投票联系题
投票联系题
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=http://www.mamicode.com/‘{$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="http://www.mamicode.com/投票" /> 62 <input type="button" id="jg" value="http://www.mamicode.com/查看结果" onclick="showjg()" /> 63 <input type="button" id="fanhui" value="http://www.mamicode.com/返回" 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");
投票联系题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。