首页 > 其他 > 详细

投票练习

时间:2016-05-08 15:14:28      阅读:222      评论:0      收藏:0      [点我收藏+]

<body><div style="margin-left:200px; margin-top:100px; " >
<?php
include "./tp.class.php";
$db = new TP();
$sql = "select * from tpz where Ids = 1";
$attr = $db->Query($sql);
?>
<h1><?php echo $attr[0][1];?></h1>
<div style=" display:block;" id="Q">
<form action="tj.php" method="post">
<?php
$sql1 = "select Idr,options from tp";
$attr1 = $db->Query($sql1);
foreach($attr1 as $v)
{

echo "<input type=‘checkbox‘ value={$v[0]} name=‘tp[]‘/>".$v[1]."<br><br>";
}
?>
<br />
<br />
<div><input type="submit" value="提交" />&nbsp;&nbsp;&nbsp;<input type="button" value="查看结果" onclick="tj()" /></div>
</form>
</div>
</div>

<div style="margin-left:200px; margin-top:100px;">
<div style="display:none;" id="H">
<form action="main.php" method="post">
<?php
$sql1 = "select * from tp where Timudaihao = 1";
$attr1 = $db->Query($sql1);
$sql2 = "select sum(numbers) from tp";
$c = $db->Query($sql2);
foreach($attr1 as $v)
{
$b = $v[2]/$c[0][0]*100;
$b1 = number_format($b,2);
echo "<table>
<tr>
<td style=‘width:100px‘>{$v[1]}</td>
<td><div style=‘border:0px solid;background-color:#EDEDED; width:200px; height:10px;‘ >
<div style=‘background-color:#FF0000; width:{$b1}%; height:10px;‘></div>
</div></td>
<td style=‘width:100px‘>{$v[2]}&nbsp;({$b1}%)</td>
</tr>
</table>";
}
?>
<br />
<br />
<div><input type="button" value="返回" onclick="fh()" /></div>
</form>
</div>
</div>
<script>
function tj()
{
document.getElementById("Q").style.display = "none";
document.getElementById("H").style.display = "block";
}
function fh()
{
document.getElementById("Q").style.display = "block";
document.getElementById("H").style.display = "none";
}
</script>
</body>

 

 

处理:

<?php
include "tp.class.php";
$db = new TP();
$tp = $_POST["tp"];
if(!empty($tp))
{
foreach ($tp as $v)
{
$sql1 = "select numbers from tp where Idr= {$v[0]}";
$b1 = $db->Query($sql1);
$b2 = $b1[0][0]+1;
$sql = "update tp set numbers={$b2} where Idr = {$v[0]}";
$a = $db->Query($sql,1);
}
if($a)
{
header("location:main.php");
}
else
{
echo "失败!";
}
}
else
{
header("location:main.php");
}

 

 

类:

<?php
class TP
{
public $host = "localhost";
public $uid = "root";
public $pwd = "";

public function Query($sql,$type=0,$db="news")
{
$d = new MySQLi($this->host,$this->uid,$this->pwd,$db);
!mysqli_connect_error() or die("连接失败!");
$result = $d->query($sql);
if($type==0)
{
return $result->fetch_all();
}
else
{
return $result;
}
}
}

投票练习

原文:http://www.cnblogs.com/1116zsc/p/5470543.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!