内测投票
create table DiaoYanTiMu
( Ids int(10) auto_increment not null primary key(),//把所需要的都寫(xiě)上中間不需要符號(hào)隔開(kāi),設(shè)自增長(zhǎng)列類型必須是int,主鍵的話必須不能為空not null,
Title varchar(50) not null
);//這里的;一定不要忘記,要不然報(bào)錯(cuò)還找不出來(lái),
insert into?DiaoYanTiMu values(null,"35歲的發(fā)展方向");//因?yàn)樵O(shè)了自增長(zhǎng)列,所以第一個(gè)列名Ids寫(xiě)為null,
create table DiaoYanXuanXiang
( Ids int(10) not null auto_increment primary key,
Options varchar(50) not null,
Numbers int(10) not null,
TiMuDiaoYan int(10) not null
);
insert into DiaoYanXuanXiang values(null,"aaa",0,001);
insert into DiaoYanXuanXiang values(null,"bbb",0,001);
insert into DiaoYanXuanXiang values(null,"ccc",0,001);
insert into DiaoYanXuanXiang values(null,"ddd",0,001);
insert into DiaoYanXuanXiang values(null,"eee",0,001);
?
接下來(lái)自己做的過(guò)程中卡殼了,不知道怎么要選項(xiàng)前面的復(fù)選框出現(xiàn),沒(méi)有想到可以遍歷,而且html寫(xiě)在php中總是各種報(bào)錯(cuò),以為是不能寫(xiě)多以就不知道怎么做了,后來(lái)反應(yīng)過(guò)來(lái)是""的問(wèn)題,因?yàn)樵趐hp中輸出echo"";已經(jīng)有了"",所以里面的內(nèi)容要用'',所以被坑的不輕是真的沒(méi)有反應(yīng)過(guò)來(lái)問(wèn)題在引號(hào)上……粗心真的使不得,半個(gè)'有時(shí)候找半天發(fā)現(xiàn)是自己手誤少了,可是出來(lái)的結(jié)果直接變形
<!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>無(wú)標(biāo)題文檔</title> <style type="text/css"> #xxlist{ width:250px; height:200px} #jieguo{width:250px; height:200px} .a{float:left;} </style> </head><body> <form action="jieguo.php" method="post"> <?php include("./ChaXun.class.php");//加載封裝好的類,之前自己封裝了一個(gè),把那個(gè)copy到當(dāng)前文件夾下面了 $tp=new ChaXun(); $sql="select * from DiaoYanTiMu limit 0,1";//limit之前沒(méi)怎么用過(guò),0,1,表示越過(guò)0行,從第一行開(kāi)始 $attr=$tp->Query($sql);//就一行數(shù)據(jù) //var_dump($attr);$tmmc=$attr[0][1]; $tmdh=$attr[0][0]; echo"<div>題目名稱:{$tmmc}</div>"; $sqlxx = "select * from DiaoYanXuanXiang where TiMuDiaoYan='{$tmdh}'";//選項(xiàng)表中的TiMuDiaoYan就是主鍵Ids $attrxx=$tp->Query($sqlxx); //var_dump($attrxx); echo"<div id='xxlist'>"; foreach($attrxx as $v)//遍歷$attrxx {echo"<div><input type='checkbox' value='{$v[0]}' name='xx[]'/><span>{$v[1]}</span> </div>"; } ?> <input type="submit" value="提交" /> <input type="button" value="查看結(jié)果" id="check" οnclick="ShowJieGuo()" /> </form> </div> <div id="jieguo" style="display:none"><?php$sqlsum="select sum(Numbers) from DiaoYanXuanXiang where TiMuDiaoYan='{$tmdh}'";$attrsum=$tp->Query($sqlsum);foreach($attrxx as $v){ $xxm=$v[1];//var_dump($xxm);$no=$v[2];$bfb=($no/$attrsum[0][0])*100;$bfb=round($bfb,2);echo"<div style='width:250px;height:30px'><span class='a'>{$xxm}</span><div class='a' style='width:100px; height:10px; border:solid 1px red'><div style='width:{$bfb}%; height:10px; background-color:red'></div></div><span class='a'>{$no} </span><span class='a'>{$bfb}%</sapn> </div>";}?><input type="button" value="返回" id="fanhui" οnclick="ShowList()" /> </div> </body> <script type="text/javascript"> function ShowJieGuo() {document.getElementById("xxlist").style.display="none";document.getElementById("jieguo").style.display="block"; } function ShowList() {document.getElementById("xxlist").style.display="block";document.getElementById("jieguo").style.display="none";} </script></html>
提交之后,轉(zhuǎn)換到另一個(gè)jieguo.php頁(yè)面,處理提交需要處理的內(nèi)容
<?php $attr=$_POST["xx"]; var_dump($attr); include("./ChaXun.class.php"); $db=new ChaXun(); foreach($attr as $v) {$sql="update DiaoYanXuanXiang set Numbers=Numbers+1 where Ids='{$v}'";$db->Query($sql,1);//這里需要注意,type默認(rèn)為0發(fā)表查詢,這里update是更改不是查詢所以type的值需要改變 } header("location:toupiao.php");//處理結(jié)束跳轉(zhuǎn)回toupiao.php頁(yè)面?
轉(zhuǎn)載于:https://www.cnblogs.com/nannan-0305/p/5470578.html
總結(jié)
- 上一篇: 使用xcap进行更改报文并进行回放以及回
- 下一篇: 编写DBUtil及测试