首页 >后端开发 >php教程 >php数据库批量删除方法

php数据库批量删除方法

一个新手
一个新手原创
2017-10-18 09:10:322067浏览

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Title</title>
</head>
<body>
<?php
$db = new Mysqli("localhost","root","root","db_0808");
//!$db?"":die("链接错误");
empty(mysqli_connect_error())?"":die("链接错误");
$sql = "select * from student where is_delete=&#39;0&#39;";
//$data = $db->query($sql)->fetch_all();
?>
<form action="batch_delete.php" method="post">
<table border="1">
    <tr>
        <td>id</td>
        <td>名字</td>
        <td>性别</td>
        <td>班级</td>
        <td>生日</td>
        <td>操作</td>
        <td>选择</td>
    </tr>
    <?php
    $result=$db->query($sql);
    while ($data=$result->fetch_row()){
//    foreach ($data as $i){
        if ($data[2]==1){
            $data[2]="男";
        }else if ($data[2]==0){
            $data[2]="女";
        }else{
            $data[2]="保密";
        }
        echo "<tr>
                 <td>{$data[0]}</td>
                 <td>{$data[1]}</td>
                 <td>{$data[2]}</td>
                 <td>{$data[3]}</td>
                 <td>{$data[4]}</td>
                 <td><a href=&#39;delete.php?id={$data[0]}&#39;>删除</a>
                     <a href=&#39;xiugai.php?id={$data[0]}&#39;>修改</a>
                 </td>
                 <td><input type=&#39;checkbox&#39; name=&#39;ids[]&#39; value=&#39;{$data[0]}&#39;></td>                 //
              </tr>";
    }
    ?>
</table>
<form action="batch_delete.php" method="post">
<input type="submit" value="删除所选">
</form>
    <a href="add.php">新增用户</a>
</body>
</html>
<?php
/**
 * Created by fcc
 * User: Administrator
 * Date: 2017/10/17
 * Time: 15:16 */$ids=$_POST[&#39;ids&#39;];$db=new Mysqli("localhost","root","root","db_0808");empty(mysqli_connect_error())?"":die("链接错误");//$sql="DELETE FROM student WHERE Sno=&#39;{$id}&#39;";//彻底删除foreach ($ids as $i){$sql = "update student set is_delete = &#39;1&#39; where Sno= &#39;{$i}&#39;";//表面删除if ($db->query($sql)){    header("location:CURD.php");
};
};

以上是php数据库批量删除方法的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn