php批量删除记录

<?php
$arr = $_POST["item"];
$db = new mysqli("localhost","root","12345678","heiheihei");
//foreach($arr as $v)
//{
//    $sql = "delete from contacts WHERE id='{$v}'";
//    $db->query($sql);
//}
$str = implode("','",$arr);//拼接字符,
$sql = "delete from contacts WHERE id in('{$str}')";
//2','8','4
if($db->query($sql))//判断是否查询成功,
{
    header("location:shouye.php");
    //成功就跳转
}



?>

  

posted @ 2021-12-07 13:14  充实地生活着  阅读(35)  评论(0编辑  收藏  举报