How to delete multiple pieces of data in thinkphp: 1. Open the template page file; 2. Write ""; 3. Use the "function del(){...}" method to delete multiple pieces of data.
The operating environment of this tutorial: Windows 7 system, ThinkPHP version 5, Dell G3 computer.
How to delete multiple pieces of data in thinkphp?
ThinkPHP code example to implement batch deletion of data
ThinkPHP implements batch deletion of data The principle is very simple, just write In this way, it is an array. The delete function del() of action is as follows:
/** **删除函数支持删除多条和一个 **/ 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('删除失败!'); } }
Recommended learning: "thinkPHP Video Tutorial"
The above is the detailed content of How to delete multiple pieces of data in thinkphp. For more information, please follow other related articles on the PHP Chinese website!