Home >Backend Development >PHP Problem >How to delete data in batches in php
php method to delete data in batches: first on the article list page [list.php]; then name the multi-select box [$del_id[]], the value is the article ID number; finally process the page [del. php].
php method to delete data in batches:
1. First, on the article list page (list.php), Name the multi-select box: "$del_id[]", and the value is the article ID number.
例如(list.php): <form name="del_form" action="del.php" method="post"> <?php $result=mysql_query("select * from news"); while($rs=mysql_fetch_array($result)){ ?> <input name="del_id[]" type="checkbox" id="del_id[]" value="<?=$rs[id]?>" /><?=$rs[title]?> <?php } ?> </form>
2. Processing page (del.php):
<?php if($del_id!=""){ $del_num=count($del_id); for($i=0;$i<$del_num;$i++){ mysql_query("Delete from news where id='$del_id[$i]'"); } echo("<script type='text/javascript'>alert('删除成功!');history.back();</script>"); }else{ echo("<script type='text/javascript'>alert('请先选择项目!');history.back();</script>"); } ?>
If you want to learn more about programming, please pay attention to the php training column!
The above is the detailed content of How to delete data in batches in php. For more information, please follow other related articles on the PHP Chinese website!