您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php如何实现批量删除数据

2024/2/29 19:58:38发布30次查看
php如何实现批量删除数据
首先在前端将需要删除的数据的id,以数组形式提交到后端php;然后在php中通过“$_get”来获取要删除的数据id,最后进行连接mysql数据库,将数据逐个删除或使用“in”一次性删除即可。
示例代码
html:
<form id="form2" name="form2" method="post" action="del_product.php"> <label> <input type="checkbox" name="id[]" value="1" style="background:none; border:none;" /> 1 </label> <label> <input type="checkbox" name="id[]" value="2" style="background:none; border:none;" /> 2 </label> <label> <input type="checkbox" name="id[]" value="3" style="background:none; border:none;" /> 3 </label> <label> <input type="checkbox" name="id[]" value="4" style="background:none; border:none;" /> 4 </label> <label> <input type="checkbox" name="id[]" value="5" style="background:none; border:none;" /> 5 </label> <div style="padding-left:20px;"> <input type="button" value="全选" style="background:url(images/cheall.jpg) no-repeat; width:60px; height:23px; border:none;" onclick="selectbox('all')"/> <input type="button" value="反选" style="background:url(images/cheall.jpg) no-repeat; width:60px; height:23px; border:none;" onclick="selectbox('reverse')"/> <input type="submit" name="btnsave" style="background:url(images/cheall.jpg) no-repeat; width:60px; height:23px; border:none;" value="删除"/> </div></form>
php:
if($_post['btnsave']){ if(empty($_post['id'])){ echo"<script>alert('必须选择一个产品,才可以删除!');history.back(-1);</script>"; exit; } else { /*如果要获取全部数值则使用下面代码*/ $id= implode(",",$_post['id']); $str="delete from `product` where id in ($id)"; mysql_query($str); echo "<script>alert('删除成功!');window.location.href='product_list.php';</script>"; }}
推荐教程:《php教程》
以上就是php如何实现批量删除数据的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product