• 6.12php对数据库的删除和批量删除


    //主页

    <?php
    $bt = empty($_POST['bt'])?'':$_POST['bt'];
    $zz = empty($_POST['zz'])?'':$_POST['zz'];
    ?>
    <!DOCTYPE html>
    <html lang="zh">
    <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <!--引入bootstrap css文件-->
    <link rel="stylesheet" href="css/js/css/bootstrap.min.css"/>
    <!--引入jQuery-->
    <script src="css/js/jquery-3.3.1.min.js"></script>
    <script src="css/js/bootstrap.min.js"></script>
    <title>Document</title>
    </head>
    <body>
    <form action="" method="post">
    标题 :<input type="text" name="bt" id="" value="<?php echo $bt;?>" /><!--输上值可以保留-->
    作者 :<input type="text" name="zz" id="" value="<?php echo $zz;?>" />
    <input type="submit" name="" id="" value="查询"/>
    </form>
    <form action="piliang.php" method="post">
    <table border="1px" cellspacing="" cellpadding=""class="table table-dark">
    <tr>
    <td><input type="checkbox" onclick="quanxuan(this)"/></td>
    <td>序号</td>
    <td>标题</td>
    <td>作者</td>
    <td>来源</td>
    <td>内容</td>
    <td>发布时间</td>
    <td>修改</td>
    <td>删除</td>
    </tr>
    <?php
    $severname = "localhost";
    $dbuser = "root";
    $dbpassword = "";
    $dbname = "ceshi";
    $conn = new mysqli($severname,$dbuser,$dbpassword,$dbname);
    if($conn->connect_error){
    die("链接失败");
    }
    $sql = "select * from wz where biaoti like '%$bt%' and zuozhe like '%$zz%'";
    //一进页面两个条件为空,所以还是查询所有
    $result = $conn->query($sql);
    $attr = $result->fetch_all();
    $str = "";
    for($i=0;$i<count($attr);$i++){
    $str.="<tr>";
    $str.="<td><input type='checkbox' name='ck[]' id='' value='{$attr[$i][0]}' class='qx'/></td>";
    //name='ck[]' 如果不加[]后面传值没法传数组,后面名字不用[];
    for($j=0;$j<count($attr[$i]);$j++){
    $str.="<td>{$attr[$i][$j]}</td>";
    }
    $str.="<td><a href='xiugai.php?bs={$attr[$i][0]}'>修改</a></td>";
    $str.="<td><a href='shanchu.php?bs={$attr[$i][0]}'>删除</a></td>";
    $str.="</tr>";
    }
    echo $str;
    ?>
    </table>
    <input type="submit" value="批量删除"/>
    </form>
    <a href="xinzeng.php">新增</a>
    </body>
    </html>
    <script type="text/javascript">
    function quanxuan(t) {
    var aa = document.getElementsByClassName("qx");
    for (var i=0;i<aa.length;i++) {
    if (t.checked==true) {
    aa[i].checked=true;
    }else if(t.checked==false){
    aa[i].checked=false;
    }
    //aa[i].checked = t.checked?true:false;
    }

    }
    </script>

    //删除

    <?php
    $bs=$_GET['bs'];
    $severname = "localhost";
    $dbuser = "root";
    $dbpassword = "";
    $dbname = "ceshi";
    $conn = new mysqli($severname,$dbuser,$dbpassword,$dbname);
    $sql = "delete from wz where id ='$bs'";
    $result = $conn->query($sql);
    header("Location:0612.php");
    ?>

    //批量删除

    <?php
    $ckattr = $_POST['ck'];
    $str = join("','",$ckattr);
    echo($str);
    $conn =new mysqli("localhost","root","","ceshi");
    if($conn->connect_error){
    die("链接失败");
    }
    $sql = "delete from wz where id in ('{$str}')";
    if($result = $conn->query($sql)){
    header("Location:0612.php");
    };
    ?>

  • 相关阅读:
    Insus Meta Utility
    The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
    Insus Binary Utility
    asp.net实现文件下载功能
    Column 'Column Name' does not belong to table Table
    程序已被编译为DLL,怎样去修改程序功能
    如何在Web网站实现搜索功能
    如何把数据流转换为二进制字符串
    Asp.net更新文件夹的文件
    如何显示中文月份
  • 原文地址:https://www.cnblogs.com/sunhao1987/p/9174943.html
Copyright © 2020-2023  润新知