I believe many friends still don’t know how to batch delete unwanted data. To use PHP to batch delete data, we need to combine it with the in condition of mysql. Achieved, I guess everyone will understand how to do it after reading this sentence. Now I will analyze the process of batch deletion of data in detail for friends who need to know.
We delete the required sql syntax
delete from aaaa where id in (1,2,3) where 1,2,3 is the record we need to delete
So how to do it in php
1. First, on the article list page (list.php), name the multi-select box: "$del_id[]", and the value is the article ID number.
For example (list.php):
The code is as follows | |||||
2. Processing page (del.php ):
if($del_id!=""){ |
Case analysis:
代码如下 | |
for($i=0;$i<$del_num;$i++){ |
The code is as follows | |
for($i=0;$ i<$del_num;$i++){ |
This is to get the submitted array and then we traverse each one to delete it. This is the same as our previous statement. In fact, we can improve it
The code is as follows | |||||
$ids = implode(',' ,$_POST['del_id']);
|
This can simplify a lot of statements. Of course, the above needs to determine whether the submitted one is an array. Finally, we perform code optimization and deletion of the del.php file
The code is as follows | |||||
if(is_array($del_id)){
Previous article:Teach you step by step how to do a keyword matching project (search engine) ---- Day 20, teach you how to do it on the 20th day_PHP Tutorial
Next article:11 Most Frequently Asked PHP Interview Questions_PHP Tutorial
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
When adding sublime3 to compile system php, use the PHP toolbox, cmd php -v is useless
From 1970-01-01 08:00:00
0
0
0
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|