php 資料訪問練習:投票頁面

來源:互聯網
上載者:User

標籤: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 資料訪問練習:投票頁面

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.