1.投票页面
<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <form action="toupiao.php" method="post"> <?php include("./PPO.class.php"); $db = new PPO(); $sql = "select * from diaoyantimu"; $attr = $db->Query($sql); echo "{$attr[0][1]}<br>"; $code = $attr[0][0]; $sxx = "select * from diaoyanxuanxiang where timudaihao='{$code}'"; $axx = $db->Query($sxx); foreach($axx as $v) { echo "<input type='checkbox' value='{$v[0]}' name='xx[]' />$v[1]<br>"; } ?> <input type="submit" value="投票" /> </form> </body> </html>
2.显示结果
<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <?php include("./ppo.class.php"); $db = new PPO(); $attr = $_POST["xx"]; foreach($attr as $v) { $sql = "update diaoyanxuanxiang set numbers=numbers+1 where ids='{$v}'"; $db->Query($sql,0); } //显示结果 $sql = "select * from diaoyanxuanxiang"; $shuzu = $db->Query($sql); $szs = "select sum(numbers) from diaoyanxuanxiang"; $azs = $db->Query($szs); $zs = $azs[0][0]; foreach($shuzu as $v) { $bfb = ($v[2]/$zs)*100; echo "{$v[1]}:{$v[2]}({$bfb}%)<div style='200px;height:10px; border:1px solid red;'><div style='background-color:green; {$bfb}%; height:10px'></div></div>"; } ?> </body> </html>