Maison > Article > développement back-end > 批量删除文章ID?
(list.php): <form action="del.php" method="post"> <?php $sql="select * from news where leibie='$leibieming'";$r=$mysqli->query($sql); while($rs=$r->fetch_assoc()){ ?> <input type="checkbox" value="<?=$rs[id]?>" /><?=$rs[title]?> <?php } ?> <input type="button" value="删除""></form> 2、处理惩罚页面(del.php): <?php if($del_id!=""){ $del_num=count($del_id); for($i=0;$i<$del_num;$i++){ $mysqli->query("delete news.......");} echo("<script type='text/javascript'>alert('删除乐成!');history.back();</script>"); }else{ echo("<script type='text/javascript'>alert('请先选择项目!');history.back();</script>"); } ?>
你抄漏了!
" />=$rs[title]?>
应为
" />=$rs[title]?>
另外
if($del_id!=""){
应改写为
if(isset($_POST['del_id'])){
$del_id = $_POST['del_id'];
还有
改为
否则页面无法提交
你抄漏了!
" />=$rs[title]?>
应为
" />=$rs[title]?>
另外
if($del_id!=""){
应改写为
if(isset($_POST['del_id'])){
$del_id = $_POST['del_id'];
删除的结果是 array 提示输出。
还有
改为
否则页面无法提交
修正了。
贴出你修改后的 php 代码
if(isset($_POST['del_id'])){ $del_id=$_POST['del_id']; $del_num=count($del_id); for($i=0;$i<$del_num;$i++){ $mysqli->query("delete news,newscontents from news inner join newscontents on news.Nid=newscontents.nid where news.Nid='$del_id'"); echo $del_id.'删除'; }}else{ echo("<script type='text/javascript'>alert('请先选择项目!');history.back();</script>");}
<form action="delAllZhangJie.php"method="post"><?php $Name="国际新闻"; $sql="select Nid,Title from news where Class='$Name' order by Nid desc"; $csql=$mysqli->query($sql); while($rs=$csql->fetch_assoc()){?> <input type="checkbox" name="del_id[]" value="<?=$rs['Nid']?>" />-<?=$rs['Nid']?>-<?=$rs['Title']?><br><?php }?> <input type="submit" value="删除""></form>
贴出你修改后的 php 代码
帮我看看是哪的问题咯
$mysqli->query("delete news,newscontents from news inner join newscontents on news.Nid=newscontents.nid where news.Nid='$del_id[$i]'");
echo $del_id[$i].'删除';