Home > Backend Development > PHP Tutorial > php一次性删除前台checkbox多选内容的方法

php一次性删除前台checkbox多选内容的方法

PHPz
Release: 2018-10-09 16:19:26
forward
868 people have browsed it

如何一次性删除前台checkbox多选的内容,在本文将为大家介绍下php中时如何实现的,感兴趣的你可不要错过了哈

代码如下:

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

数据用逗号隔开。

表单:

代码如下:

<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

好$ID_Dele=$_POST['ID_Dele']将会是一个数组,虽然说PHP是弱类型的,但这里可没ASP弱。

ASP可以直接:
SQL="delete from [doing] where id in ('"&ID_Dele&"')"进行删除。但PHP不能把$ID_Dele直接放进去。因为$ID_Dele可不是'1,2,3,4'哦,因为$ID_Dele是一个数组,具有键和值。
好,PHP中也不难,刚好有个函数:implode(),对了。同split()\explode()功能刚好相反的一个函数,后两者是用某字符(比如逗号)分割的,而前者则可以拼接为字符串。

因此:

代码如下:

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

更多相关教程请访问  php编程从入门到精通全套视频教程

Related labels:
php
source:jb51.net
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