zoukankan      html  css  js  c++  java
  • 批量删除

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>

    <body>

    <h1>批量删除</h1>

    <form action="pldel.php" method="post">

    <table width="100%" border="1" cellpadding="0" cellspacing="0">

    <tr>
    <td>
    <input type="checkbox" name="qx" onclick="checkall(this)" />
    代号
    </td>
    <td>名称</td>
    </tr>

    <?php
    $db = new MySQLi("localhost","root","123","mydb");
    $sql = "select * from nation";
    $result = $db->query($sql);
    while($arr = $result->fetch_row())
    {
    echo "<tr>
    <td>
    <input type='checkbox' value='{$arr[0]}' name='item[]' class='ck' />
    {$arr[0]}
    </td>
    <td>{$arr[1]}</td>
    </tr>";
    }

    ?>

    </table>

    <input type="submit" value="批量删除" />

    </form>
    <script type="text/javascript">

    function checkall(qx)
    {
    var ck = document.getElementsByClassName("ck");

    if(qx.checked)
    {
    for(var i=0;i<ck.length;i++)
    {
    ck[i].setAttribute("checked","checked");
    }
    }
    else
    {
    for(var i=0;i<ck.length;i++)
    {
    ck[i].removeAttribute("checked");
    }
    }
    }

    </script>
    </body>
    </html>





    <?php

    $arr = $_POST["item"];

    $db = new MySQLi("localhost","root","123","mydb");

    /*foreach($arr as $v)
    {
    $sql = "delete from nation where code='{$v}'";
    $db->query($sql);
    }*/

    $str = implode("','",$arr);

    $sql = "delete from nation where code in('{$str}')";
    //n003','n004','n005','n006
    if($db->query($sql))
    {
    header("location:test.php");
    }

  • 相关阅读:
    shell编程基础干货
    HIVE的高级操作
    Linux service,挂载,定时任务等常用服务
    Linux(二)高级文本处理
    Linux基本使用命令
    07-MySQL 架构介绍
    06-Re: 视图&过程&触发器
    05-安装 MySQL5.7
    [04] 继承&聚合&war
    [03] 仓库&生命周期&插件目标
  • 原文地址:https://www.cnblogs.com/jc535201285/p/6434475.html
Copyright © 2011-2022 走看看