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

    这里不止用于批量删除,批量选择也是一样,主要就是用复选框进行批量选择,结合JS完成批量删除的效果。

    最终结果图:

    1、代码如下,分两个页面,下面是main1的代码

    <body>
    <h1>汽车信息</h1>
    <form action="delete.php" method="post">
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
        <tr>
            <td><input type="checkbox" name="qx" onclick="quanxuan(this)" />代号</td><!--设置复选框并添加点击事件-->
            <td>名称</td>
        </tr>
    <?php
    require "DBDA.class.php";
    $db=new DBDA();
    
    $sql="select * from car";
    $arr=$db->query($sql);
    
    foreach($arr as $v)
    {
        echo "<tr>
            <td><input type='checkbox' name='ck[]' class='ck' value='{$v[0]}'>{$v[0]}</td>
            <td>{$v[1]}</td>
        </tr>";    
    }
    ?>
    </table><br />
    
    <input type="submit" value="批量删除" />
    </form>
    </body>
    <script>
    function quanxuan(qx)
    {
        var ck=document.getElementsByClassName("ck");//提取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>
    </html>

     2、delete页面代码:

    <?php
    $arr = $_POST["ck"];//提取数据,取到数组
    
    require "DBDA.class.php";
    $db = new DBDA();
    
    $str = implode("','",$arr);//数组组成字符串
    
    $sql = "delete from car where code in('{$str}')";
    echo $sql;
    if($db->query($sql,0))
    {
        header("location:main1.php");
    }
  • 相关阅读:
    CentOS 6 + bochs-2.6 + gdb 调试 linux 0.11 —— 成功
    操作系统原理——互斥同步
    CentOS 6 bochs-2.6 gdb 调试 linux 0.11——bochsrc-fd1-gdb.bxrc
    vim+xxd=强大的十六进制编辑器
    【t043】成绩查询
    【u251】心灵的抚慰
    【t041】距离之和
    【t086】防护伞
    Java Web整合开发(37) -- SVN
    ubuntu命令
  • 原文地址:https://www.cnblogs.com/mengshenshenchu/p/6801730.html
Copyright © 2011-2022 走看看