PHP-MySQL練習:簡單投票

來源:互聯網
上載者:User

標籤:

首頁面代碼:

<!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><style>.liu{    float:left;}</style><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title></head><body><div id="timu" style="display:block"><form action="tpcl.php" method="post"><?phpinclude("database.class.php");$tm=new database();$tm_result=$tm->query("select title from tm");echo $tm_result[0][0]."<br>";$tmxx_result=$tm->Query("select * from tmxx");foreach($tmxx_result as $v){    echo "<input type=‘checkbox‘ value=‘{$v[0]}‘ name=‘xx[]‘/>{$v[1]}<br>";}?><input type="submit" value="投票" />&nbsp;<input  type="button" value="查看結果" onclick="show()"/></form></div><div id="jieguo" style="display:none"><?php$answer=$tm->Query("select options,numbers from tmxx");$sum=$tm->Query("select sum(numbers) from tmxx where tmcode=1");foreach($answer as $a){    $bfb=round(($a[1]/$sum[0][0])*100,2);    echo "<div><span class=‘liu‘>{$a[0]}&nbsp;</span>               <div class=‘liu‘ style=‘width:100px;height:10px;background-color:#CDCDCD‘>               <div class=‘liu‘ style=‘width:{$bfb}%;height:10px;background-color:red‘></div></div>&nbsp;               <span>{$a[1]}</span>&nbsp;               <span>({$bfb}%)</span>         </div>";}?><div><input type="button" value="返回" onclick="show1()" /></div></div></body></html><script>function show (){    document.getElementById("timu").style.display="none";    document.getElementById("jieguo").style.display="block";}function show1(){    document.getElementById("timu").style.display="block";    document.getElementById("jieguo").style.display="none";}</script>

幕後處理代碼:

<?php$xx=$_POST["xx"];include("database.class.php");$tpcl=new database();if(!empty($xx)){    foreach($xx as $v)    {        $tpcl_result=$tpcl->Query("select numbers from tmxx where code=‘{$v[0]}‘");        $tpcl_result=$tpcl_result[0][0]+1;        $tpcl_result1=$tpcl->Query("update tmxx set numbers=$tpcl_result where code=‘{$v[0]}‘",1);    }    header("location:tp.php");}else{    header("location:error.php");}

 

PHP-MySQL練習:簡單投票

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.