php数据库批量删除

2018-06-22 05:29:45来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

<!DOCTYPE html>
<html lang="en">
<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='0'";
//$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='delete.php?id={$data[0]}'>删除</a>
                     <a href='xiugai.php?id={$data[0]}'>修改</a>
                 </td>
                 <td><input type='checkbox' name='ids[]' value='{$data[0]}'></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['ids'];

$db=new Mysqli("localhost","root","root","db_0808");
empty(mysqli_connect_error())?"":die("链接错误");
//$sql="DELETE FROM student WHERE Sno='{$id}'";//彻底删除

foreach ($ids as $i){
$sql = "update student set is_delete = '1' where Sno= '{$i}'";//表面删除
if ($db->query($sql)){
    header("location:CURD.php");
};
};

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:phpstorm中配置使用svn详细步骤

下一篇:最好最实用的二次开发教程 cms