• 12-29 批量删除


    <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("../fengzhuang/DBDA.class.php");
    $db = new DBDA();

    $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>

    效果:

    删除页面

    <?php
    $ck = $_POST["ck"];

    include("../fengzhuang/DBDA.class.php");
    $db = new DBDA();

    //第一种方式
    /*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:main.php");

  • 相关阅读:
    浏览器兼容之background-size
    bootstrap学习之全局样式
    bootstrap dropdown的点击变为:hover 后自动下拉
    看完了《缔造企鹅》
    2015年阅读记录
    博士论文致谢 作一下
    如何将Visio转化为EPS? For Latex
    《乌合之众》 古斯塔夫·勒庞
    笑傲江湖
    社会化推荐(一) 理论和实践 对科学的思考
  • 原文地址:https://www.cnblogs.com/F4natasy/p/6233234.html
Copyright © 2020-2023  润新知