时时商务社区
标题:
ThinkPHP实现批量删除数据的代码实例
[打印本页]
作者:
yj1281
时间:
2018-2-14 05:56
ThinkPHP实现批量删除数据原理很简单,只需在模板页面里面写上
这样传过来就是一个数组,action的删除函数del()如下:
/**
**删除函数支持删除多条和一个
**/
function del(){
//dump($_GET['id']);
//$name = strtolower($_GET['_URL_'][0]); //获取当前模块名
$name = $this->getActionName();
$model = D($name);//获取当期模块的操作对象
$id = $_GET['id'];
//判断id是数组还是一个数值
if(is_array($id)){
$where = 'id in('.implode(',',$id).')';
}else{
$where = 'id='.$id;
}
//dump($where);
$list=$model->where($where)->delete();
if($list!==false) {
$this->success("成功删除{$list}条!");
}else{
$this->error('删除失败!');
}
}
更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《
ThinkPHP入门教程
》、《
thinkPHP模板操作技巧总结
》、《
ThinkPHP常用方法总结
》、《
smarty模板入门基础教程
》及《
PHP模板技术总结
》。
希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。
您可能感兴趣的文章:
PHP 批量删除 sql语句
PHP 批量删除数据的方法分析
php中批量删除Mysql中相同前缀的数据表的代码
php批量删除cookie的简单实现方法
基于ThinkPHP实现批量删除
PHP批量删除jQuery操作
欢迎光临 时时商务社区 (http://bbs.4435.cn/)
Powered by Discuz! X3.2