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):
The code is as follows |
Copy Code |
<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" (' 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 |
Copy Code |
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 |
Copy Code |
$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 |
copy code |
<?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 '; } } } |