投票
投票页面
主页面
<!doctype html> <html> <head> <meta charset="utf-8"> <title>投票</title> </head> <body> <h1>投票界面</h1> <form action="tpchuli.php" method="post"> <?php require_once "./DBDA.php"; $db = new DBDA; $sql = "select * from dytm"; $arr = $db->query($sql); //var_dump($arr); foreach($arr as $v){ echo $v[1]; $sqlxx = "select * from dyxx where timudaihao = '{$v[0]}'"; $arrxx = $db->query($sqlxx); foreach($arrxx as $vxx){ echo "<div><input type='checkbox' name='ck[]' value='{$vxx[0]}'>$vxx[1]</div>"; } } ?> <input type="submit" value="提交"> <br /> <a href="./jieguo.php"><button type="button">查看结果</button></a> </form> </body> </html>
处理界面
<?php $ck = $_POST["ck"]; //var_dump($ck); require_once "./DBDA.php"; $db = new DBDA(); $str = implode("','",$ck); $sql = "update dyxx set numbers = numbers+1 where ids in ('{$str}')"; //var_dump($sql); $arr = $db->query($sql,1); if($arr){ header("location:toupian.php"); }else{ echo"false"; }
结果界面
<!doctype html> <html> <head> <meta charset="utf-8"> <title>结果</title> <style type="text/css"> .wai{width:500px; height:20px;} .li{width:500px; height:20px;} </style> </head> <body> <?php require_once "./DBDA.php"; $db = new DBDA; $sql = "select * from dytm"; $arr = $db->query($sql); //var_dump($arr); foreach($arr as $v){ echo "<div>$v[1]</div>"; $sqlall = "select sum(numbers) from dyxx where timudaihao = '{$v[0]}'"; $arrall = $db->query($sqlall); $sqlxx = "select * from dyxx where timudaihao = '{$v[0]}'"; $arrxx = $db->query($sqlxx); foreach($arrxx as $vxx){ $vxx[2]; $arrall[0][0]; $bfb = ($vxx[2]/$arrall[0][0])*100; echo "<div>{$vxx[1]}<div class='wai'><div class='li' style='width:{$bfb}%; background-color:#603'></div></div>{$bfb}%   {$vxx[2]}</div>"; } // var_dump($arrxx); } ?> <a href="./toupian.php"><button type="button">返回</button></a> </body> </html>
效果图