Home  >  Article  >  Backend Development  >  ThinkPHP code example to implement batch deletion of data_PHP tutorial

ThinkPHP code example to implement batch deletion of data_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:26:29791browse

The principle of batch deletion of data in ThinkPHP is very simple, just write a542812dd1484533867695dceb95a863Passed in this way, it is an array. The deletion 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('删除失败!');
  }
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824660.htmlTechArticleThinkPHP The principle of batch deletion of data is very simple, just write input name='id[] in the template page ' type='checkbox' value='{$vo.id}' class="noborder" passed in this way is an array...
Statement:
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