日期:2014-05-17  浏览次数:20458 次

批量删除文章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>"); 

?> 


在网上抄回来的,del_id 这个变量是怎么传递的?

------解决方案--------------------
你抄漏了!
<input type="checkbox" value="<?=$rs[id]?>" /><?=$rs[title]?>
应为
<input type="checkbox" name="del_id[]" value="<?=$rs[id]?>" /><?=$rs[title]?>

另外
if($del_id!=""){
应改写为
if(isset($_POST['del_id'])){
  $del_id = $_POST['del_id'];
------解决方案--------------------
还有
<input type="button" value="删除"">
改为
<input type="submit" value="删除"">
否则页面无法提交
------解决方案--------------------
贴出你修改后的 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].'删除';