php method for deleting foreground checkbox multiple selections at once
- 2020-09-28 08:49:51
- OfStack
SQL : $SQL="delete from `doing` where id in ('1,2,3,4')";
Data is separated by commas.
Form:
<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>
Ok $ID_Dele=$_POST['ID_Dele'] will be an array, although PHP is said to be weak, but not as weak as ASP.
ASP can be direct:
SQL="delete from [doing] where id in ('" & ID_Dele & ")" to be deleted. But PHP can't just put $ID_Dele in. Because $ID_Dele is not '1,2,3,4', because $ID_Dele is an array with keys and values.
Ok, so PHP is not hard either, there happens to be a function: implode(), right. A function that is the exact opposite of split()\explode(), where the latter two are separated by a character such as a comma, and the former can be concatenated as a string.
Therefore:
$ID_Dele= implode(",",$_POST['ID_Dele']);
$SQL="delete from `doing` where id in ($ID_Dele)";