I believe many friends do not know how to bulk delete the data, single use PHP bulk delete data We need to combine MySQL in the condition to achieve, this estimate everyone read this sentence to understand how to do, below I will give a friend need to know detailed analysis of the bulk delete data process.
We delete the required SQL syntax
Delete from AAAA where ID in (1,2,3) This 1,2,3 is the record we need to delete.
So how do you do it in PHP?
1, first in the article List page (list.php), will select the basket named: "$del _id[]", the value is the article ID number.
For example (list.php):
code is as follows |
&nbs P; |
<form name= "Del_form" action= "del.php" method= "POST" > < br> <?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 (' Delete succeeded! '); History.back ();</script> "); }else{ echo (" <script type= ' text/javascript ' >alert (' Please select the item first! '); History.back ();</script> "); } |
Case study:
The bulk core code above is table Single-name for del_id[] and
The code is as follows |
|
for ($i =0; $i < $del _num; $i + +) { mysql_query ("Delete from News where id= ' $del _id[$i]"); } |
This is getting the submitted array, and then we're going to go through a strip of it. It's a little smaller than our previous statement, but we can actually improve
The code is as follows |
|
$ids = Implode (', ', $_post[' del_id ')); $sql = "Delete from AAAA where ID in ($ids)"; mysql_query ($SQL); |
So you can Jane a lot of statements oh, of course, the above need to judge the submission over is not an array, and finally we have the del.php file code optimization delete operation
code is as follows |
&nbs P; |
<?php if (Is_array ($del _id)) { $ids = Implode (', ', $_post[' del_id ']); $sql = "Delete from AAAA where ID in ($ids)"; if (mysql_query ($SQL)) { echo ' delete succeeded '; } Else { echo ' delete failed '; } } } |