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";
    }
  • 相关阅读:
    博客
    欧几里得算法的时间复杂度
    Linux伙伴系统1
    伙伴系统
    websocket
    Colored Sticks POJ
    Repository HDU
    Phone List HDU
    Hat’s Words HDU
    HDU1800 字典树写法
  • 原文地址:https://www.cnblogs.com/ping04/p/7837589.html
Copyright © 2011-2022 走看看