11月3日上午PHP練習《投票》

來源:互聯網
上載者:User

標籤:lock   tle   fetch   sql   display   bsp   sub   cli   action   

1.建立資料庫

 

表1:DiaoYanTiMu

表2:DiaoYanXuanXiang

 

2.頁面 

頁面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><style type="text/css">#fanhui{ display:none}</style></head><body><form action="tpchuli.php" method="post">
<?php$db = new  MySQLi("localhost","root","123","mydb");$sql = "select * from diaoyantimu";$result = $db->query($sql);$attr = $result->fetch_all();foreach($attr as $v){    echo "<div>{$v[1]}</div>";        $sxx = "select * from diaoyanxuanxiang where timudaihao=‘{$v[0]}‘";        $rxx = $db->query($sxx);        $axx = $rxx->fetch_all();        $bs = 0;    if(!empty($_GET["a"]))    {        $bs = $_GET["a"];    }        $s = $bs==1?"none":"block";        echo "<div id=‘toupiao‘ style=‘display:{$s}‘>";    foreach($axx as $v1)    {        echo "<div><input type=‘checkbox‘ name=‘tp[]‘ value=‘{$v1[0]}‘ />{$v1[1]}</div>";    }    echo "</div>";        $s1 = $bs==0?"none":"block";        //顯示投票結果    echo "<div id=‘jieguo‘ style=‘display:{$s1}‘>";        foreach($axx as $v2)    {        $v2[2]; //當前選項的人數        //求總人數        $szrs = "select sum(numbers) from diaoyanxuanxiang where timudaihao=‘{$v[0]}‘";        $rzrs = $db->query($szrs);        $azrs = $rzrs->fetch_row();        $azrs[0]; //總人數                $bfb = ($v2[2]/$azrs[0])*100;                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>";    }        echo "</div>";}?>
<input type="submit" value="投票" />
<input type="button" id="jg" value="查看結果" onclick="showjg()" /><input type="button" id="fanhui" value="返回" onclick="showtp()"  /></form></body><script type="text/javascript">function showjg(){    document.getElementById("jieguo").style.display="block";    document.getElementById("toupiao").style.display="none";    document.getElementById("jg").style.display="none";    document.getElementById("fanhui").style.display="block";    }function showtp(){    document.getElementById("jieguo").style.display="none";    document.getElementById("toupiao").style.display="block";    document.getElementById("jg").style.display="block";    document.getElementById("fanhui").style.display="none";}</script></html>

頁面2:處理頁面

<?php$attr = $_POST["tp"];$str = implode("‘,‘",$attr);$sql = "update diaoyanxuanxiang set numbers = numbers+1 where ids in(‘{$str}‘)";$db = new MySQLi("localhost","root","123","mydb");$db->query($sql);header("location:toupiao.php?a=1");

 

11月3日上午PHP練習《投票》

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.