How to batch delete data in a data table in PHP

Source: Internet
Author: User
In PHP, how does one batch delete data in a data table so that data in a data table needs to be deleted in batches? how can I write code!


Reply to discussion (solution)

Delete tbl_name where id in ($ var1, $ var2 ,...)

This is a $ _ POST array. multiple content submitted in a form is transmitted to PHP using $ _ POST,
PHP retrieves $ _ POST and uses foreach to traverse $ _ POST. In this example, DELETE 'DB _ name' WHERE id = ". $ _ POST [] is used.

This is a $ _ POST array. multiple content submitted in a form is transmitted to PHP using $ _ POST,
PHP retrieves $ _ POST and uses foreach to traverse $ _ POST. In this example, DELETE 'DB _ name' WHERE id = ". $ _ POST [] is used.
How to put the ID submitted in FORM in an array...

When you generate the checkbox, you can specify it as an array, and then submit it as an array.
Then you can traverse the deletion or in ()... deletion operations.

$ _ POST is an array.
Every tag is an input, right? Each input has a name value,
After the LZ check box is selected, click submit. $ _ POST ['here is the name value of input '] will be submitted to the PHP page.
If selected, true is not selected, and false is selected.
Use
If ($ _ POST ['input name value']) {
Echo 'I have been selected ';
// Here, write the MYSQL deletion statement.
}
This if statement is set to a while statement.

$ _ POST is an array.
Every tag is an input, right? Each input has a name value,
After the LZ check box is selected, click submit. $ _ POST ['here is the name value of input '] will be submitted to the PHP page.
If selected, true is not selected, and false is selected.
Use
If ($ _ POST ['input name value']) {
Echo 'I have been selected ';
// Here, write the MYSQL deletion statement.
}
This if statement is set to a while statement.
Actually, you don't need a while loop. I did this.

Include (".. /conn. php "); $ array = implode (", ", $ _ POST ['flags']); $ query =" delete from tbl_user where ID in ($ array )"; $ SQL = mysql_query ($ query); if ($ SQL) {echo "script" alert ('deleted successfully'); window. location. href = 'show _ user. php 'script ';} else {echo "script alert ('deletion failed'); window. location. href = 'show _ user. php 'script ';}

Write the text box as follows:

When you post a file, you can get it on the server: $ id = $ _ POST ['id']; select the column and obtain the value of the column.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.