分两个页面,要点:提交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>

效果图:

2016/3/30  ①投票checkbox  ②进度条两个div套起百分比控制内div(width) &lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;     ③数据库test2 表 diaoyan...   35岁发展方向投票-LMLPHP

第二个页面

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>

效果图:

2016/3/30  ①投票checkbox  ②进度条两个div套起百分比控制内div(width) &lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;     ③数据库test2 表 diaoyan...   35岁发展方向投票-LMLPHP2016/3/30  ①投票checkbox  ②进度条两个div套起百分比控制内div(width) &lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;     ③数据库test2 表 diaoyan...   35岁发展方向投票-LMLPHP

05-21 21:35