一、首先要了解sql语句$SQL=delete from `user` where id in (1,2,4);表单大概是:form act
首先要了解sql语句
$SQL="delete from `PHP100` where id in(1,2,4)";
表单大概是:
<form act
<input type="checkbox"value="1"/>
<input type="checkbox"value="2"/>
<input type="checkbox"value="3"/>
<input type="checkbox"value="4"/>
<inputtype="submit"/>
</form>
php函数主要用到implode
$ID_Dele=implode(",",$_POST['ID_Dele']);
$SQL="delete from `user` where id in($ID_Dele)";
二、还可以使用循环语句来删除
1、首先在文章列表页面(list.php),将多选筐命名为:“$del_id[]”,值为文章ID号。
2、处理页面(del.php):
一个简单示例
现有一个学生信息数据库,需要一次性删除多条记录
创建一个名为del.php的文件
代码如下:
<form action="sc.php"method=post>
<table border=1 width=60%align=center>
<caption>学生信息表</caption>
<th>选项</th><th>学号</th><th>姓名</th><th>性别</th><th>电话</th>
<?php
$link=mysql_connect("localhost","root","");
mysql_select_db("zs");
$exec="select * from student";
$result=mysql_query($exec);
while($rs=mysql_fetch_object($result))
{
$id=$rs->sID;
$name=$rs->sName;
$sex=$rs->sSex;
$phone=$rs->sPhone;
?>
<tr>
<td> <inputtype=checkbox name=de[] value=<?php echo$id?>></td><td><?phpecho$id?></td><td><?phpecho$name?></td><td><?phpecho$sex?></td><td><?phpecho$phone?></td>
</tr>
<?php
}
mysql_close();
?>
</table>
<center><inputtype=submitvalue="删除"></center>
</form>
这个文件主要用来陈列数据库中的数据,并显示出来。
再建立一个名为sc.php的文件,其中代码如下:
<?php
$link=mysql_connect("localhost","root","");
mysql_select_db("zs");
$id=$_POST['de'];
foreach($id as $ide){
$exec="delete from student where sID=$ide";
$result=mysql_query($exec);
if((mysql_affected_rows()==0) or (mysql_affected_rows==-1))
{
echo "没有找到记录,或者删除时出错";
exit;
}
else{
echo "学生信息已经删除";
}
}
mysql_close();
?>
用foreach的方式,分别将记录删除。
详细出处参考:http://www.jb51.net/article/22216.htm
联系客服