国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > PHP > 正文

php查詢(xún)操作實(shí)現(xiàn)投票功能

2020-03-22 18:08:59
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
本文實(shí)例為大家分享了php查詢(xún)操作實(shí)現(xiàn)投票功能的代碼,供大家參考,具體內(nèi)容如下題目:解題方法匯總:
方法一:
1. 投票主頁(yè)面:
!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 #list width:400px; height:300px;}#jieguo width:400px; height:300px;} float:left;} /style /head body form action="TouChuLi.php" method="post" include ("DBDA.class.php");$db=new DBDA();//從調(diào)研題目表中找出題目代號(hào)和名稱(chēng)$sql="select * from diaoyantimu limit 0,1";$arr=$db- query($sql);$tmmc=$arr[0][1];$tmdh=$arr[0][0];echo " div h2 {$tmmc}: /h2 /div //從調(diào)研選項(xiàng)表中輸出選項(xiàng)內(nèi)容:$sqlxx="select * from diaoyanxuanxiang where timudaihao='{$tmdh}'";$arrxx=$db- query($sqlxx);echo " div id='list' foreach ($arrxx as $v) echo " div input type='checkbox' value='{$v[0]}' name='xx[]' {$v[1]} /div br /
//計(jì)算總?cè)藬?shù):$sqlzs="select sum(numbers) from diaoyanxuanxiang where timudaihao='{$tmdh}'";$zrs=$db- query($sqlzs);foreach ($arrxx as $v) $name=$v[1]; $number=$v[2]; if($zrs[0][0]==0) $bfb = 0; else $bfb = ($number/$zrs[0][0])*100; $bfb=round($bfb,2); echo " div span {$name} /span div div /div /div span {$number} /span span {$bfb}% /span /div br / input type="button" value="返回" id="fanhui" /div script function Showjieguo() document.getElementById("list").style.display="none"; document.getElementById("jieguo").style.display="block";function Showfanhui() document.getElementById("list").style.display="block"; document.getElementById("jieguo").style.display="none"; /script /body /html 2.處理投票頁(yè)面:
$arr=$_POST["xx"];include ("../DBDA.class.php");$db=new DBDA();
$sql = "update diaoyanxuanxiang set numbers = numbers+1 where ids = '{$v}'"; $db- Query($sql,1);//1代表$sql的類(lèi)型header ("location:TouPiao.php");3. 建立訪(fǎng)問(wèn)數(shù)據(jù)庫(kù)的類(lèi),封裝用于引用:
//執(zhí)行一個(gè)sql語(yǔ)句,返回相應(yīng)的結(jié)果class DBDA public $host="localhost";//數(shù)據(jù)庫(kù)服務(wù)器地址 public $uid="root";//數(shù)據(jù)庫(kù)用戶(hù)名 public $password="";//數(shù)據(jù)庫(kù)密碼 //執(zhí)行SQL語(yǔ)句的方法 //參數(shù)里面:$sql代表要執(zhí)行的sql語(yǔ)句;$type是sql語(yǔ)句的類(lèi)型,0代表查詢(xún),1代表其他(增刪改);$db代表要操作的數(shù)據(jù)庫(kù) function Query($sql,$type=0,$db="mydb") //造連接對(duì)象 $dbconnect=new MySQLi($this- host,$this- uid,$this- password,$db); //判斷連接是否出錯(cuò) !mysqli_connect_error() or die("連接失敗!"); //執(zhí)行sql語(yǔ)句 $result=$dbconnect- query($sql); //判斷SQL語(yǔ)句類(lèi)型 if($type==0) //如果是查詢(xún)語(yǔ)句返回結(jié)果集的二維數(shù)組 return $result- fetch_all(); else //如果是其他語(yǔ)句,返回true或false return $result;方法二:1. 投票主頁(yè)面:
html head meta http-equiv="Content-Type" content="text/html; charset=utf-8" / title 投票 /title style float:left;} /style /head body form action="TouChuLi.php" method="post" include ("../DBDA.class.php");$db=new DBDA();//從調(diào)研題目表中找出題目代號(hào)和名稱(chēng)$sql="select * from diaoyantimu limit 0,1";$arr=$db- query($sql);$tmmc=$arr[0][1];$tmdh=$arr[0][0];echo " div h2 {$tmmc}: /h2 /div //從調(diào)研選項(xiàng)表中輸出選項(xiàng)內(nèi)容:$sqlxx="select * from diaoyanxuanxiang where timudaihao='{$tmdh}'";$arrxx=$db- query($sqlxx);echo " div id='list' foreach ($arrxx as $v) echo " div input type='checkbox' value='{$v[0]}' name='xx[]' {$v[1]} /div br /
input type="submit" value="提交" a href="ChaKan.php" input type="button" value="查看結(jié)果" id="check" /a /form /body /html 2. 處理投票頁(yè)面:
$arr=$_POST["xx"];include ("../DBDA.class.php");$db=new DBDA();
$sql = "update diaoyanxuanxiang set numbers = numbers+1 where ids = '{$v}'"; $db- Query($sql,1);//1代表$sql的類(lèi)型header ("location:TouPiao.php");3. 查看投票結(jié)果頁(yè)面:
html head meta http-equiv="Content-Type" content="text/html; charset=utf-8" / title 查看結(jié)果 /title style float:left;} /style /head body include ("../DBDA.class.php");$db=new DBDA();//從調(diào)研題目表中找出題目代號(hào)和名稱(chēng)$sql="select * from diaoyantimu limit 0,1";$arr=$db- query($sql);$tmmc=$arr[0][1];echo " div h2 {$tmmc}: /h2 /div //從調(diào)研選項(xiàng)表中輸出選項(xiàng)內(nèi)容:$sqlxx="select * from diaoyanxuanxiang where timudaihao='{$arr[0][0]}'";$arrxx=$db- query($sqlxx);//計(jì)算總?cè)藬?shù):$sqlzs="select sum(numbers) from diaoyanxuanxiang where timudaihao='{$arr[0][0]}'";$zrs=$db- query($sqlzs);foreach ($arrxx as $v) $name=$v[1];//調(diào)研項(xiàng)目名稱(chēng) $number=$v[2];//選擇該項(xiàng)的人數(shù) //判斷總?cè)藬?shù)是否為0 if($zrs[0][0]==0) $bfb = 0; else $bfb = ($number/$zrs[0][0])*100;//求百分比 $bfb=round($bfb,2); //取小數(shù)點(diǎn)后兩位 echo " div span {$name} /span div div /div /div span {$number} /span span {$bfb}% /span br / /div br / br / a href="TouPiao.php" input type="button" value="返回" /a /body /html 顯示結(jié)果:以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)php程序設(shè)計(jì)有所幫助。PHP教程

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 班玛县| 咸丰县| 前郭尔| 吉木萨尔县| 巨野县| 绵阳市| 雅安市| 山阴县| 兰溪市| 治多县| 临朐县| 乌苏市| 新河县| 山阳县| 泽库县| 桐城市| 顺义区| 南宁市| 濮阳市| 阿拉善左旗| 罗平县| 抚州市| 延川县| 阿拉善左旗| 壶关县| 柘城县| 个旧市| 怀柔区| 大方县| 临漳县| 汉沽区| 鄯善县| 榆林市| 枝江市| 涿鹿县| 南阳市| 普安县| 西林县| 湘阴县| 金塔县| 湾仔区|