分两个页面,要点:提交form 相连action method  两个页面可以合成一个页面action传到自身页面   但分开较清晰

第一个页面vote.php

 <!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">
*
{
margin:0px auto;
padding:0px;
}
h3
{
margin:10px;
}
.diyiceng
{
height:220px;
width:200px;
background-color:#FFF;
position:absolute;
visibility:visible;
left:10px;
top:40px;
}
.dierceng
{
height:220px;
width:800px;
background-color:#FFF;
position:absolute;
visibility:hidden;
left:0px;
top:0px;
}
.xuanxiang
{
position:absolute;
}
.jindu
{
width:200px;
height:10px;
position:absolute;
left:100px;
border:solid #999 1px;
}
.jindutiao
{ height:8px;
position:absolute;
background-color:#0F0;
border:solid 1px #00FF00;
}
.shuzi
{
position:absolute;
left:320px;
}
.baifenbi
{
position:absolute;
left:350px;
}
</style>
</head> <body> <h3>35岁发展方向</h3> <div class="diyiceng" id="diyiceng">
<form action="votechuli.php" method="post">
<?php $db=new mysqli("localhost","root","123","test2");
!mysqli_connect_error()or die("连接错误"); $sql="select * from DiaoYanXuanXiang";
$resulttp=$db->query($sql); while($row = $resulttp->fetch_row())
{ //print_r($row);
echo "<div><input type='checkbox' name='test[]' value='".$row[0]."'/>".$row[1]."</div><br />";
} ?> <input type="submit" name="submit" value="提交" />&nbsp;&nbsp;
<input type="button" name="chakan" value="查看结果" onclick="xianshi()"/>
</form>
<?php
$db=new mysqli("localhost","root","123","test2");
!mysqli_connect_error()or die("连接错误"); $sql="select * from DiaoYanXuanXiang";
$result=$db->query($sql); echo "<div class='dierceng' id='yincang'>";
echo "<form>"; $sqlsum = "select SUM(numbers) from DiaoYanXuanXiang";
$resultsum = $db->query($sqlsum);
$aa = $resultsum->fetch_row();
$zongshu = $aa[0]; while($rowjg = $result->fetch_row())
{
$xuanxiang = $rowjg[1];
$shuliang = $rowjg[2];
$baifenbi = $shuliang/$zongshu*100;
$baifenbi1=round($baifenbi,1);//对小数取一位 echo "<div><div class='xuanxiang'>".$xuanxiang."</div>
<div class='jindu'><div class='jindutiao' style='width:".$baifenbi."%'></div></div>
<div class='shuzi'>".$shuliang."</div>
<div class='baifenbi'>".$baifenbi1."%</div></div><br /><br />";
} echo "<input type='button' name='fanhui' value='返回' onclick='buxianshi()' />";
echo "</form>";
echo "</div></div>"; ?>
</body>
</html>
<script>
function xianshi()
{
var a=document.getElementById("yincang");
if(a.style.visibility="hidden")
{
a.style.visibility="visible";
} }
function buxianshi()
{
var a=document.getElementById("yincang");
if(a.style.visibility="visible")
{
a.style.visibility="hidden";
} } </script>

效果图:

第二个页面

votechuli.php

 <!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>
</head> <body>
<?php
$test=$_POST["test"]; //1.造连接对象
$db=new mysqli("localhost","root","123","test2");
//2.判断是否连接成功
!mysqli_connect_error()or die("连接失败"); for($i=0;$i<count($test);$i++)
{
$sql="update DiaoYanXuanXiang set numbers=numbers+1 where ids='".$test[$i]."'"; $result=$db->query($sql);//为什么query后要加($sql,0)1代表增删改 变化的一面 0代表 查询 不变的一面 } //判断是否修改成功
if($result)
{
header("Location:vote.php");
}
else
{
echo "修改失败!";
} ?>
</body>
</html>

效果图:

最新文章

  1. python 查找指定内容的txt文件
  2. 第七课——iOS数据持久化
  3. 【python cookbook】【数据结构与算法】16.筛选序列中的元素
  4. Maven详解 之 聚合与继承
  5. ActiveMQ, RabbitMQ和ZeroMQ 选型关注点
  6. 用Autohotkey让powerpoint幻灯片一直播放
  7. html5的改变
  8. file_get_contents post数据
  9. json中关于jo.[]中字符串一致的问题
  10. Android之SharedPreferences内部原理浅析
  11. Nessus更新到8.3.0
  12. asp.net core mvc 在中间件中使用依赖注入问题:System.InvalidOperationException: Cannot resolve scoped service &#39;IXXXService&#39; from root provider.
  13. Ext中 grid 设置行样式
  14. 第八节 JS运动基础
  15. 基于uFUN开发板的RGB调色板
  16. 关于CentOS 6下Hadoop占用系统态CPU高的处理办法【转】
  17. Qt之QLocalServer
  18. php使用date()函数时,提示的警告
  19. OC学习那些事:第一个OC类
  20. 磁盘io和吞吐量

热门文章

  1. python基础知识05-控制流程
  2. 洛谷 1067 NOIP2009 普及组 多项式输出
  3. keepalived安装脚本
  4. 关于构造函数什么值传递给他的实例,只有this和prototype
  5. 大数据学习——yarn集群启动
  6. CDOJ 1218 Pick The Sticks
  7. python-001 第一个Python3.x程序 hello world
  8. zoj 2829 Beautiful Number
  9. HDU 5245
  10. ubuntu使用git提交github时,执行pull或者push命令要重新输入用户名和密码