首頁  >  文章  >  後端開發  >  php實作資料庫批量刪除的實例

php實作資料庫批量刪除的實例

黄舟
黄舟原創
2018-05-15 10:57:182492瀏覽


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Title</title>
</head>
<body>
<? =  Mysqli("localhost","root","root","db_0808"(())?"":("链接错误" = "select * from student where is_delete=&#39;0&#39;"?>
<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>
    <?=->query( (=->
         ([2]==1[2]="男"  ([2]==0[2]="女"[2]="保密" ""?>
</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