//主页
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
您35岁前的职业规划:
<form action="toupiao.php" method="post">
<table border="1px" cellspacing="" cellpadding="">
<?php
$conn = new mysqli("localhost","root","","ceshi");
if($conn->connect_error){
die("失败");
}
$sql = "select ids,xuan from zuoye";
$result= $conn->query($sql);
$attr = $result->fetch_all();
$str = "";
for($i=0;$i<count($attr);$i++){
$str.="<tr>";
$str.="<td><input type='checkbox' name='ck[]' id='' value='{$attr[$i][0]}' /></td>";
for($j=0;$j<count($attr[$i]);$j++){
$str.="<td>{$attr[$i][$j]}</td>";
}
$str.="</tr>";
}
echo $str;
?>
</table>
<input type='submit' name='' id='' value='投票' /> <a href="ckxq.php">查看详情</a>
</form>
<!--方法二直接用div拼-->
<!--<form action="tpchuli.php" method="post">
<h1>你35岁之前的规划是什么?</h1>
<div id="">
<?php
$conn = new mysqli("localhost","root","","ceshi");
if($conn->connect_error){
die("连接失败");
}
$sql = "select id,name from toupiao";
$result = $conn->query($sql);
$attr = $result->fetch_all();
$str = "";
for($i=0;$i<count($attr);$i++){
$str.= "<div><input type='checkbox' name='ck[]' value='{$attr[$i][0]}'>{$attr[$i][1]}</div>";
}
echo $str;
?>
</div>
<input type="submit" value="投票"/>
<a href="detail.php">查看详情</a>
</form>-->
</body>
</html>
//投票
<?php
$cka = $_POST['ck'];
$str = join("','",$cka);
echo($str);
$conn = new mysqli("localhost","root","","ceshi");
if($conn->connect_error){
die("失败");
}
$sql = "update zuoye set number=number+1 where xuan in ('{$str}')";
$result= $conn->query($sql);
header("Location:zy.php");
?>
//查看详情
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<style type="text/css">
.wai{
width : 200px;
height: 10px;
border: 1px solid black;
}
.nei{
height: 10px;
background: red;
}
</style>
</head>
<body>
<?php
$conn = new mysqli("localhost","root","","ceshi");
if($conn->connect_error){
die("连接失败");
}
$sql_sum = "select sum(number) from zuoye";
$result_sum = $conn->query($sql_sum);
$attr_sum = $result_sum->fetch_row();
$sql = "select xuan,number from zuoye";
$result = $conn->query($sql);
$attr = $result->fetch_all();
$str = "";
for($i=0;$i<count($attr);$i++){
$bfb = $attr[$i][1]/$attr_sum[0]*100;
$str.="<div><span>{$attr[$i][0]}</span><span>{$bfb}%</span></div>
<div class='wai'><div class='nei' style='{$bfb}%'></div></div>";
}
echo $str;
?>
</body>
</html>