zoukankan      html  css  js  c++  java
  • 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";
    }
     
  • 相关阅读:
    错题集-index.html
    面向对象-原型
    jQuery案例
    jQuery报错
    关于《哈利波特》书的购买方案
    《大道至简》读后感
    网络助手之NABCD
    返回一个二维整数数组中最大联通子数组的和
    返回一个二维整数数组中最大子数组的和。
    返回一个整数数组中最大子数组的和(环)(已更正)
  • 原文地址:https://www.cnblogs.com/cmzhphp2017/p/7752884.html
Copyright © 2011-2022 走看看