• 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";
    }
  • 相关阅读:
    Python开发【第六篇】循环语句
    Python开发【第四篇】语句与函数
    Python开发【第三篇】数据类型
    Python开发【第二篇】:初始Python
    2019-10-11入博客第一篇文章
    vim学习2-文档编辑
    vim学习1-入门指令
    linux学习9-进程管理知识
    linux学习8-正则表达式基础
    linux学习7-数据流重定向
  • 原文地址:https://www.cnblogs.com/ping04/p/7837589.html
Copyright © 2020-2023  润新知