php 投票

1、投票主界面(问题界面)

<?php
$db = new Mysqli("localhost","root","root","db_0808");
$sql = "select * from vote_category ";
$result=$db->query($sql);
$data_category=$result->fetch_all();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table border="1">
<?php
foreach($data_category as $item){
echo "<tr><th> <a href='vote.php?id={$item[0]}&is_radio={$item[2]}'>{$item[1]}</a></th></tr>";
}
?>
</table>

</body>
</html>
2、投票选项界面
<?php
$category_id=$_GET['id'];
$is_radio=$_GET['is_radio'];
$db = new Mysqli("localhost","root","root","db_0808");
$sql = "select * from vote_info WHERE category_id={$category_id}";
$result=$db->query($sql);
$data=$result->fetch_all();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>

</head>
<body>
<form action="vote_action.php" method="post">
<table border="1">
<tr>
<td>item</td>
<td>check</td>
</tr>
<?php
if($is_radio==1){
foreach($data as $i){
echo "<tr><td>{$i[1]}</td><td><input type='radio' name='item' value='{$i[0]}'></td></tr>";
}
}else{
foreach($data as $i){
echo "<tr><td>{$i[1]}</td><td><input type='checkbox' name='item[]' value='{$i[0]}'></td></tr>";
}
}
?>
</table>
<input type="submit" value="submit">
</form>
</body>
</html>
3、投票处理文件
<?php
$item=$_POST['item'];
$db = new Mysqli("localhost","root","root","db_0808");
if(is_array($item)){
$str=implode(",",$item);
$sql="update vote_info set count=count+1 where id in ({$str})";
}else{
$sql="update vote_info set count=count+1 where id={$item}";
}

$result=$db->query($sql);
if($result){
echo "success";
}

转载于:https://www.cnblogs.com/ping04/p/7837589.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值