实例四投票
2016-06-17 14:52
113 查看
显示页面
<!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"> #list{ width:250px; height:200px} #jieguo{ width:250px; height:200px} .x{float:left} </style> </head> <body> <form action="chuli.php" method="post"> <?php include("DBDA.class.php"); $db = new DBDA(); $sql = "select * from DiaoYanTiMu limit 0,1"; $attr = $db->Query($sql); $tmmc = $attr[0][1]; $tmdh = $attr[0][0]; echo "<div>题目名称:{$tmmc}</div>"; $sqlxx = "select * from DiaoYanXuanXiang where TiMuDaiHao = '{$tmdh}'"; $attrxx = $db->Query($sqlxx); echo "<div id='list'>"; foreach($attrxx as $v) { echo "<div> <input type='checkbox' value='{$v[0]}' name='xx[]' /> <span>{$v[1]}</span> </div>"; } ?> <input type="submit" value="提交" /> <input type="button" value="查看结果" id="check" onclick="ShowJieGuo()" /> </form> </div> <div id="jieguo" style="display:none"> <?php $sqlsum ="select sum(Numbers) from DiaoYanXuanXiang where TiMuDaiHao = '{$tmdh}'"; $attrsum = $db->Query($sqlsum);//所有人数 foreach($attrxx as $v) { $name = $v[1]; //选项名 $number = $v[2]; //选择该项的人数 $bfb = ($number/$attrsum[0][0])*100; $bfb = round($bfb,2); //取小数点后两位 echo "<div style='width:250px; height:30px'> <span class='x'>{$name}</span> <div class='x' style='width:100px; height:8px; border:1px solid red'> <div style='width:{$bfb}%; height:8px; background-color:red'></div> </div> <span class='x'>{$number} </span> <span class='x'>{$bfb}%</span> </div>"; } ?> <input type="button" value="返回" id="fanhui" onclick="ShowList()" /> </div> <script type="text/javascript"> function ShowJieGuo() { document.getElementById("list").style.display = "none"; document.getElementById("jieguo").style.display = "block"; } function ShowList() { document.getElementById("list").style.display = "block"; document.getElementById("jieguo").style.display = "none"; } </script> </body> </html>
处理页面
<?php $attr = $_POST["xx"]; include("DBDA.class.php"); $db = new DBDA(); foreach($attr as $v) { $sql = "update DiaoYanXuanXiang set Numbers = Numbers+1 where Ids = '{$v}'"; $db->Query($sql,0); } header("location:index.php");
引用类
<?php class DBDA { public $host="localhost"; //服务器地址 public $uid="root"; //用户名 public $pwd=""; //密码 public $dbconnect; //连接对象 //操作数据库的方法 //$sql代表需要执行的sql语句 //$type代表SQL语句的类型,1代表查询,2代表增删改 //$dbname代表操作的数据库名称 function Query($sql,$type=1,$dbname="1") { //造对象建连接 $this->dbconnect=new mysqli($this->host,$this->uid,$this->pwd,$dbname); //判断连接是否出错 if (!mysqli_connect_error()) {//连接成功执行sql语句 $result=$this->dbconnect->query($sql); if($type==1) { //查询语句 return $result->fetch_all(); } else { //其他语句 return $result; } } else { echo "连接失败"; } } }
相关文章推荐
- 实验四主存空间的分配与回收
- PHP 将数组打乱 shuffle函数的用法及简单实例
- 阿里云服务器linux系统远程连接
- linux 服务器间copy 文件
- HTTP原理之HTTP报文(1) 方法
- JavaScript强化教程-JS面向对象编程
- 数据库复习总结
- 关于Android的Cordova插件plugin OnActivityResult无效的问题
- elasticsearch安装记录
- 办公软件Cnskype for business自动化系统的作用
- 通用视图-分开处理GET、POST请求
- 实验四 主存空间的分配与回收
- mvc ajax提交数组参数(转)
- Node学习笔记(四):gulp+express+io.socket部署angularJs2(填坑篇)
- 与useradd命令相关的两个默认配置文件
- 前端的小玩意(2)jQuery的选择器大全
- 未来需要学习的技术
- Unix或Linux中&、jobs、fg、bg等命令的使用方法
- 通过百度地图API获取经纬度以及两点间距离
- ANDROID动态加载 使用SO库时要注意的一些问题