1. 程式人生 > >php 數據訪問練習:投票頁面

php 數據訪問練習:投票頁面

val remove border bootstra title else spl itl 數據

<!--投票界面-->

<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 數據訪問練習:投票頁面