本节内容:
PHP批量删除数据
1,sql语句
复制代码 代码示例:
$SQL="delete from `PHP100` where id in (1,2,4)";
2,表单
复制代码 代码示例:
<form action="" 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>
php函数中使用implode:
$ID_Dele= implode(",",$_POST['ID_Dele']);
$SQL="delete from `user` where id in ($ID_Dele)";
附,implode
将数组变成字符串。
语法: string implode(string glue, array pieces);
返回值: 字符串
函数种类: 资料处理
内容说明
本函数将数组的内容组合成一个字符串,参数 glue 是字之间的分隔符号。
例子:
复制代码 代码示例:
<?
$colon_separated = implode ( ":" , $array );
echo $colon_separated ;
?>
全选
<script>function checkall(form, prefix, checkall) {
for(var i = 0; i < form.elements.length; i++) {
var e = form.elements[i];
if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
e.
checked = form.elements[checkall].checked;
}
}
}</script>
<form>
<input type="checkbox" name="chkall" onclick="checkall(this.form, 'del', 'chkall')">全选
<input type="checkbox" name="del[]" value=1>删除1
<input type="checkbox" name="del[]" value=2>删除2
<input type="checkbox" name="del[]" value=3>删除3
<input type="checkbox" name="del[]" value=4>删除4
<input type="submit" name="modsubmit" value="提交">
</form>