码迷,mamicode.com
首页 > Web开发 > 详细

php 数据访问练习:投票页面

时间:2017-09-05 21:51:35      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:ane   数据   progress   meta   mysqli   sqli   new   cat   查看   

<!--投票界面-->

<html>
<head>
<title></title>
<meta charset="UTF-8"/>

<link rel="stylesheet" type="text/css" href="bootstrap.min.css"/>
<script src="bootstrap.min.js"></script>
<script src="jquery-1.11.2.min.js"></script>

<style type="text/css">
*{
margin: 0px auto;
padding: 0px;
}
.wid{
max-width: 300px;
}
.zhezhao{
height: 260px;
width: 321px;
background-color: white;
/*border: 1px solid;*/
position: absolute;
top: 149px;
left: 519px;
}
.fanhui{
position: absolute;
top: 418px;
left: 237px;
height: 39px;
width: 150px;
/*border: 1px solid;*/
background-color: white;
}
</style>
</head>

<form action="tianjia.tp.php" method="post">
<body>
<div style="height: 50px;"></div>

<?php
$da = new MySQLi("localhost","root","","php_zuoye");
$sql = "select numbers from diaoyanxuanxiang";
$result = $da->query($sql);
$arr = $result->fetch_all();

foreach($arr as $v){
$z[] = $v[0];
}

$a1 = $z[0]/($z[0]+$z[1]+$z[2]+$z[3]+$z[4])*100;
$a1 = round($a1);

$a2 = $z[1]/($z[0]+$z[1]+$z[2]+$z[3]+$z[4])*100;
$a2 = round($a2);

$a3 = $z[2]/($z[0]+$z[1]+$z[2]+$z[3]+$z[4])*100;
$a3 = round($a3);

$a4 = $z[3]/($z[0]+$z[1]+$z[2]+$z[3]+$z[4])*100;
$a4 = round($a4);

$a5 = $z[4]/($z[0]+$z[1]+$z[2]+$z[3]+$z[4])*100;
$a5 = round($a5);



?>

<div class="panel panel-primary" style="max-width: 900px;">
<div class="panel-heading">
<h3 class="panel-title">调查问卷</h3>
</div>
<div class="panel-body">
<label for="name">一、晚上回家干什么</label>
<div class="checkbox" >
<label><input type="checkbox" name="wt1[0]" value="1"
id="kds">
看电视
</label>

<?php
echo "
<div class=‘progress progress-striped wid‘
style=‘position: relative;‘><!--进度条-->
<div class=‘progress-bar progress-bar-info‘ role=‘progressbar‘
aria-valuenow=‘60‘ aria-valuemin=‘0‘ aria-valuemax=‘100‘
style=‘width:
{$a1}%;‘>
</div>
<span style=‘right:136px; position: absolute;‘>
{$a1}%
</span>
</div>";
?>
</div>
<div class="checkbox">
<label><input type="checkbox" name="wt1[1]" value="2"
id="wyx">
玩游戏
</label>

<?php
echo "
<div class=‘progress progress-striped wid‘
style=‘position: relative;‘><!--进度条-->
<div class=‘progress-bar progress-bar-info‘ role=‘progressbar‘
aria-valuenow=‘60‘ aria-valuemin=‘0‘ aria-valuemax=‘100‘
style=‘width: {$a2}%;‘>
</div>
<span style=‘right:136px; position: absolute;‘>
{$a2}%
</span>
</div>"
?>
</div>
<div class="checkbox">
<label><input type="checkbox" name="wt1[2]" value="3"
id="js">
健身
</label>

<?php
echo "
<div class=‘progress progress-striped wid‘
style=‘position: relative;‘><!--进度条-->
<div class=‘progress-bar progress-bar-info‘ role=‘progressbar‘
aria-valuenow=‘60‘ aria-valuemin=‘0‘ aria-valuemax=‘100‘
style=‘width: {$a3}%;‘>
</div>
<span style=‘right:136px; position: absolute;‘>
{$a3}%
</span>
</div>"
?>
</div>
<div class="checkbox">
<label><input type="checkbox" name="wt1[3]" value="4"
id="xzy">
写作业
</label>

<?php
echo "
<div class=‘progress progress-striped wid‘
style=‘position: relative;‘><!--进度条-->
<div class=‘progress-bar progress-bar-info‘ role=‘progressbar‘
aria-valuenow=‘60‘ aria-valuemin=‘0‘ aria-valuemax=‘100‘
style=‘width: {$a4}%;‘>
</div>
<span style=‘right:136px; position: absolute;‘>
{$a4}%
</span>
</div>"
?>
</div>
<div class="checkbox">
<label><input type="checkbox" name="wt1[4]" value="5"
id="gdx">
搞对象
</label>

<?php
echo "
<div class=‘progress progress-striped wid‘
style=‘position: relative;‘><!--进度条-->
<div class=‘progress-bar progress-bar-info‘ role=‘progressbar‘
aria-valuenow=‘60‘ aria-valuemin=‘0‘ aria-valuemax=‘100‘
style=‘width: {$a5}%;‘>
</div>
<span style=‘right:136px; position: absolute;‘>
{$a5}%
</span>
</div>"
?>
</div>

<div>
<button type="submit" class="btn btn-primary" id="tijiao"
onclick="return tishi()">
投 票
</button>
<button type="button" class="btn btn-primary"
id="chakan" onclick="set(zhezhao),remove(fanhui)">
查看结果
</button>
</div>
</div>

<div class="zhezhao" id="zhezhao" style="">

</div>

<div id="fanhui" class="fanhui" style="display: none;">
<button type="button" class="btn btn-primary"
style="width: 100px;" onclick="remove(zhezhao),set(fanhui)">
返 回
</button>
</div>
</div>

</body>
</form>
</html>
<script type="text/javascript">
var zhezhao = document.getElementById("zhezhao");
var chakan = document.getElementById("chakan");
var fanhui = document.getElementById("fanhui");
var kds = document.getElementById("kds");
var wyx = document.getElementById("wyx");
var js = document.getElementById("js");
var xzy = document.getElementById("xzy");
var gdx = document.getElementById("gdx");

function set(zz){
zz.style.setAttribute("display","none");
}
function remove(zzz){
zzz.style.removeAttribute("display");
}
function tishi(){
if(!kds.checked && !wyx.checked && !js.checked && !xzy.checked && !gdx.checked){
alert("请选择投票选项!");
return false;
}else{
alert("投票成功!");
return true;
}
}
</script>

<!--投票处理界面-->

<?php
header("Content-type:text/html;charset=utf-8");

$arr = $_POST["wt1"];

$db = new MySQLi("localhost","root","","php_zuoye");
if(mysqli_connect_error()){
echo "lianjieshibai";
}
$sql = "update diaoyanxuanxiang set
numbers = numbers + 1 where ids=‘{$arr[0]}‘|| ids=‘{$arr[1]}‘
|| ids=‘{$arr[2]}‘|| ids=‘{$arr[3]}‘|| ids=‘{$arr[4]}‘";

if($db->query($sql)){
header("location:toupiao.php");
}else{
echo "失败";
}
?>

php 数据访问练习:投票页面

标签:ane   数据   progress   meta   mysqli   sqli   new   cat   查看   

原文地址:http://www.cnblogs.com/liuyuze/p/7481810.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!