一次性删除多条记录,对于比较多的信息,如果没有批量删除功能是非常麻烦的。这样就方便多了。
一个简单示例:现有一个学生信息数据库,需要一次性删除多条记录
<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> <input type=checkBox name=de[] value=<?PHP echo $id?>></td><td><?PHP echo $id?></td><td><?PHP echo $name?></td><td><?PHP echo $sex?></td><td><?PHP echo $phone?></td>
</tr>
<?PHP
}
MysqL_close();
?>
</table>
<center><input type=submit value="删除"></center>
</form>
<?PHP
$link=MysqL_connect("localhost","");
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的方式,分别将记录删除。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。