Home > Backend Development > PHP Problem > How to implement multi-select deletion function in php

How to implement multi-select deletion function in php

藏色散人
Release: 2023-03-06 14:20:01
Original
2676 people have browsed it

How to implement multi-selection deletion in php: first create a file containing the multi-selection content of the front-end checkbox; then combine the array elements into a string through the implode function; and finally use SQL statements to achieve deletion.

How to implement multi-select deletion function in php

Recommended: "PHP Video Tutorial"

php method to delete the multi-selection content of the front-end checkbox at one time

The code is as follows:

SQL:$SQL="delete from `doing` where id in ('1,2,3,4')";
Copy after login

The data is separated by commas.

Form:

The code is as follows:

<form action="?action=doing" method="post"> 
<input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="1"/> 
<input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="2"/> 
<input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="3"/> 
<input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="4"/> 
<input type="submit"/> 
</form>
Copy after login

Okay$ID_Dele=$_POST['ID_Dele'] will be an array. Although PHP is weakly typed, It's not as weak as ASP here.

ASP can delete directly:

SQL="delete from [doing] where id in ('"&ID_Dele&"')". But PHP cannot put $ID_Dele directly into it. Because $ID_Dele is not '1,2,3,4', because $ID_Dele is an array with keys and values.

Okay, it’s not difficult in PHP. There happens to be a function: implode(), that’s right. A function that has exactly the opposite function to split()\explode(). The latter two are separated by a certain character (such as a comma), while the former can be spliced ​​into a string.

Therefore:

The code is as follows:

$ID_Dele= implode(",",$_POST[&#39;ID_Dele&#39;]); 
$SQL="delete from `doing` where id in ($ID_Dele)";
Copy after login

The above is the detailed content of How to implement multi-select deletion function in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template