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

    1.批量删除主页

    <!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>
    <form action="shanchu.php" method="post">
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
        <tr>
            <td><input type="checkbox" id="qx" onclick="xuanzhong()" />全选</td>
            <td>代号</td>
            <td>名称</td>
        </tr>
        
        <?php
        include("../toupiao/PPO.class.php");
        $db = new PPO();
        
        $sql = "select * from nation";
        $attr = $db->Query($sql);
        
        foreach($attr as $v)
        {
            echo "<tr>
            <td><input type='checkbox' name='ck[]' class='ck' value='{$v[0]}' /></td>
            <td>{$v[0]}</td>
            <td>{$v[1]}</td>
        </tr>";
        }
        
        ?>
        
    </table>
    <input type="submit" value="删除" onclick="return tishi()" />
    </form>
    </body>
    <script type="text/javascript">
        function xuanzhong()
        {
            //取全选按钮的选中状态
            var zt = document.getElementById("qx").checked;
            
            //让下面所有的checkbox选中状态改变
            var ck = document.getElementsByClassName("ck");
            
            for(var i=0;i<ck.length;i++)
            {
                if(zt)
                {
                    ck[i].setAttribute("checked","checked");
                }
                else
                {
                    ck[i].removeAttribute("checked");
                }
            }
        }
        
        function tishi()
        {
            //找所有选中项
            var ck = document.getElementsByClassName("ck");
            
            var str = "";
            
            for(var i=0;i<ck.length;i++)
            {
                if(ck[i].checked)
                {
                    str += ck[i].value+",";
                }
            }
            
            return confirm("确定要删除以下数据么:"+str+"");
        }
    </script>
    </html>

    2.做删除处理页面

    <?php
    $ck = $_POST["ck"];
    
    include("../toupiao/PPO.class.php");
    $db = new PPO();
    
    //第一种方式
    /*foreach($ck as $v)
    {
        $sql = "delete from nation where code='{$v}'";
        $db->Query($sql,0);
    }*/
    
    //第二种方式
    //in ('','','','','')
    $str = implode("','",$ck);
    
    $str = "('{$str}')"; 
    
    $sql = "delete from nation where code in {$str}";
    $db->Query($sql,0);
    
    header("location:piliangshanchu.php");
  • 相关阅读:
    【Life】 今天的思考
    【openpyxl】 关于 单元格背景色 的疑惑
    【xlwings】 wps 和 office 的excel creat_sheet区别
    [git] git error: unable to unlink old
    【python tkinter】对于窗口存在的认识
    【求教 探讨】python tkinter的messagebox
    [python]近日 用3种库 实现简单的窗口 的回顾~
    AE(After Effects)的简单使用——记一次模板套用的过程
    python3爬虫应用--爬取网易云音乐(两种办法)
    【KataDaily 191015】Sort the Gift Code
  • 原文地址:https://www.cnblogs.com/chaochao00o/p/6236089.html
Copyright © 2011-2022 走看看