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";
}

最新文章

  1. [转]7个高性能JavaScript代码高亮插件
  2. [听听音乐]when you believe [singer: mariah carey]
  3. 64位Ubuntu下的Eclipse、ADT终于可以生成R.java了,虚机也可以正常建立
  4. 8 Things Every Person Should Do Before 8 A.M.
  5. WPF异常“调用线程无法访问此对象,因为另一个线程拥有该对象 ”
  6. JMeter 压力测试使用CSV参数
  7. Hive总结(七)Hive四种数据导入方式
  8. Tomcat利用MSM实现Session共享方案解说
  9. POJ 1035 Spell checker 字符串 难度:0
  10. JS计算混合字符串长度
  11. Sahi (2) —— https/SSL配置(102 Tutorial)
  12. print(array)时array中间是省略号没有输出全部的解决方法
  13. 3D单机游戏《天鹰教》源码发布(二)
  14. GUI程序设计3
  15. libjpeg.a exists or that its path is correct
  16. h5禁用手机input点击放大
  17. ZOJ 3689 Digging(DP)
  18. 判断Map集合中是否存在某一个key
  19. bzoj 4591 [Shoi2015]超能粒子炮&#183;改——组合数前缀和
  20. .Vue 文件 ES6 语法 webstorm 中的一个识别Bug

热门文章

  1. Spring框架学习-Spring的AOP概念详解
  2. openssl 安装配置
  3. LeetCode Isomorphic Strings 对称字符串
  4. 洛谷 P1340 兽径管理
  5. 解决Starting to watch source with Jekyll and Compass. Starting Rack on port 4000
  6. WPF知识点全攻略03- XAML
  7. webpack打包性能分析
  8. Mathematics-基础:散列函数
  9. tp5 -- 腾讯云cos简单使用
  10. Spring框架中的aop操作之二 通过配置文件实现增强