Home > Backend Development > PHP Tutorial > Implement batch deletion based on ThinkPHP, _PHP tutorial

Implement batch deletion based on ThinkPHP, _PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-12 09:02:27
Original
901 people have browsed it

Batch deletion based on ThinkPHP,

This article analyzes the code examples of batch deletion based on ThinkPHP, and shares it with you for your reference, the details are as follows:

Without further ado, here are the renderings:


HTML layout (based on bootstrap)

<div class="panel panel-default">
  <div class="panel-heading">
    留言列表
    <a class="btn btn-xs btn-default pull-right" href="javascript:window.history.back();">返回</a>
    <a class="btn btn-xs btn-info pull-right mr-5" id="discard" href="javascript:;">删除</a>
  </div>
  <table class="table">
    <thead>
      <tr>
        <th><input class="all" type="checkbox"/></th>
        <th>id</th>
        <th>名称</th>
        <th>邮箱</th>
        <th>内容</th>
        <th>日期时间</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody>
       <form>
         <volist name="list" id="vo" empty="$empty">
           <tr>
             <td><input name="delete[]" type="checkbox" value="{$vo.id}" /></td>
             <td>{$vo.id}</td>
             <td>{$vo.name}</td>
             <td>{$vo.email}</td>
             <td>{$vo.subject}</td>
             <td>{$vo.datetime|date="Y-m-d H:i", ###}</td>
           <td>
            <a class="delete" href="javascript:;" data-id="{$vo.id}">删除</a>
           </td>
           </tr>
         </volist>
       </form>
    </tbody>
  </table>
</div>
Copy after login

JS script processing (using ajax technology)
First determine whether there is a selected value, and if not, prompt; if so, pass it to the server for processing

/* 批量删除 */
  // 全选
  $('.all').click(function() {
    if($(this).is(':checked')) {
      $(':checkbox').attr('checked', 'checked');
    } else {
      $(':checkbox').removeAttr('checked');
    }
  });

  // 删除操作
  $('#discard').click(function() {
    if($(':checked').size() > 0) {
      layer.confirm('确定要删除吗?', {
        btn: ['确定','取消'], //按钮
        shade: false //不显示遮罩
      }, function(){
        $.post("{:U('Single/discard')}", {data: $('form').serializeArray()}, function(res) {
          if(res.state == 1) {
            layer.msg(res.message, {icon: 1, time: 1000});
          } else {
            layer.msg(res.message, {icon: 2, time: 1000});
          }
          setTimeout(function() {
            location.reload();
          }, 1000);
        });
      }, function(){
        layer.msg('取消了删除!', {time: 1000});
      });
    } else {
      layer.alert('没有选择!');
    }
  });

Copy after login

PHP code:
Get the submitted data, then loop to get the value of each id, and then perform the deletion operation.

public function discard() {
  $contact = M('contact');
  $deleteArr = I('post.data');
  for($i=0;$i<count($deleteArr);$i++) {
    $contact->delete($deleteArr[$i]['value']);
  }
  $this->ajaxReturn(array('message'=>'删除成功!'));
}
Copy after login

The above is the key code for batch deletion in ThinkPHP. I hope it will be helpful to everyone's learning.

Articles you may be interested in:

  • PHP batch deletion of data
  • PHP batch deletion of sql statements
  • PHP batch deletion of data method analysis
  • Code for batch deletion of data tables with the same prefix in Mysql in PHP
  • Code examples for PHP batch deletion and clearing UTF-8 file BOM headers
  • ThinkPHP code examples for batch deletion of data
  • php batch deletes tables with specified prefixes in the database, taking prefix_ as an example
  • A simple implementation method of php batch deleting cookies

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084603.htmlTechArticleBatch deletion based on ThinkPHP. This article analyzes the code examples of batch deletion based on ThinkPHP and shares it with everyone. For reference, the details are as follows: Without further ado, let’s start with the results...
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
Latest Issues
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
ThinkPHP Why use composer?
From 1970-01-01 08:00:00
0
0
0
thinkphp versions supported by php6
From 1970-01-01 08:00:00
0
0
0
thinkphp upload files
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template