zoukankan      html  css  js  c++  java
  • 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");
    };
    ?>

  • 相关阅读:
    读TIJ -6 类再生
    STM32 外设配置关键步骤-驱动出了问题,最好还是瞧瞧--待续
    oracle 10g 11g rac 虚拟环境切换
    UFLDL教程之(三)PCA and Whitening exercise
    VIM配置文件
    Codeforces 586D Phillip and Trains(DP)
    51Nod 1272最大距离 (树状数组维护前缀最小值)
    Codeforces 482B Interesting Array(线段树区间更新)
    Codechef Chef and Triangles(离散化+区间并集)
    POJ1655 Balancing Act(树的重心)
  • 原文地址:https://www.cnblogs.com/sunhao1987/p/9174943.html
Copyright © 2011-2022 走看看