帮我看下这段关于PHP代码那里错了,求大神指导!

<table width="100%" border="0" cellpadding="3" cellspacing="1" class="tablebg">
<tr>
<th width="100">ID</th>
<th>关键词</th>
<th width="120">查询次数</th>
<th width="80">操作</th>
<th width="40">选择</th>
</tr>
<form id="kid[]" name="kid[]" method="post" action="?action=dolistform" onsubmit="return checkform();">
<?php
echo pageshow($page,$totalpage,$total,"?action=".$action."&kw=".$kw."&");
?>
<?php
if($action=="search")
{
$where=" where";
if(!empty($kw))
{
$where.=" keyword like '%".$kw."%'";
}
else
{
$where="";
}
}
$sql="select * from ve123_search_keyword".$where;//echo $sql;
$result=$db->query($sql);
$total=$db->num_rows($result);//记录总数
$pagesize=5;//每页显示数
$totalpage=ceil($total/$pagesize);
$page=intval($_GET["page"]);
if($page<=0){$page=1;}
$offset=($page-1)*$pagesize;
$result=$db->query($sql." order by kid desc limit $offset,$pagesize");
while ($rs=$db->fetch_array($result))
{
?>
<tr>
<td><?php echo $rs["kid"]?></td>
<td><?php echo "<a target=\"_blank\" href=\"../s/?wd=".urlencode($rs["keyword"])."\" >".$rs["keyword"];?></td>
<td><?php echo $rs["hits"];?></td>
<td>
<a href="?action=modify&kid=<?php echo $rs["kid"]?>">修改</a>
<a href="?action=del&kid=<?php echo $rs["kid"];?>" onclick="if(!confirm('确认删除吗?')) return false;">删除</a> </td>
<td><input type="checkbox" name="kid[]" value="<?php echo $rs["kid"]?>" /></td>
</tr>
<?php
}
?>
<tr>
<th colspan="7">
<div align="center">
<input name="chkall" type="checkbox" id="chkall" onclick=CheckAll(this.form,'kid[]') value="checkbox">
选中本页显示的信息 <strong>操作:</strong>
<input name="do_action" type="radio" value="del" checked="checked">
删除    
<input type="submit" name="Submit" value=" 执 行 ">
</div> </th>
</tr></form>
</table>
单个(即一个一个地)删除,是可以了;但多个(批量)同时删除就不行,帮改下,能支持单个删除,也能支持批量删除,谢了!! 我只会html PHP只是刚开始学的,真的不会啊!这是我的邮箱552371423#qq.com #号改成@,谢谢了!

慕桂英3389331
浏览 146回答 3
3回答

慕盖茨4494581

给你讲一个思路,具体得程序你自己实现:先用JavaScript实现批量选取,再将要删除得id连成以,分割得字符串。再用AJAX方式或者location.href方式讲这个字符串提交给delete.php文件处理。 delete.php将字符串解析为id数组,用循环遍历数组得方式生成sql语句。,然后执行sql语句就可以了。以location.href=del.php?id=25,27,29为例<?php$conn=mysqli_connect('localhost','root','','aa');$array=explode(',',$_REQUEST['id']);for($i=0;$i<sizeof($array);$i++){$sql="DELETE FROM `bb` WHERE `id` =".$array[$i]." LIMIT 1;";$result=$conn->query($sql);}if($result){echo "删除成功";}else {echo mysqli_error($conn);}?>你先试试能不能成功

汪汪一只猫

你一定要注意页面上的checkbox一定要如同<input type="checkbox" name="id[]" value="1"><input type="checkbox" name="id[]" value="2">这样你post或者get过去之后就可以用$_REQUEST['id']取得传递过来的值然后一个foreachforeach($_REQUEST['id'] as $v) {$sql = "delete from 表 where id = '$v'";mysql_query($sql);}表名和查询的条件自己去改.... 最重要是先做好数据库的连接

心有法竹

光这一个文件帮你改不了,还需要控制删除数据的那个php文件
打开App,查看更多内容
随时随地看视频慕课网APP