Home > PHP Framework > ThinkPHP > body text

How to delete multiple pieces of data in thinkphp

藏色散人
Release: 2022-12-07 09:47:00
Original
885 people have browsed it

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.

How to delete multiple pieces of data in thinkphp

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('删除失败!');
 }
}
Copy after login

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!

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