Home > Backend Development > PHP Tutorial > About how thinkPHP implements batch deletion

About how thinkPHP implements batch deletion

不言
Release: 2023-03-30 18:56:02
Original
3499 people have browsed it

This article mainly introduces the implementation method of thinkPHP batch deletion, and analyzes the database and template operation related skills of thinkPHP to achieve batch deletion of data in the form of examples. Friends in need can refer to the following

The examples in this article describe Implementation method of batch deletion in thinkPHP. Share it with everyone for your reference, the details are as follows:

html:

<li>
  <a class="delete" href="__URL__/deleteSelected/navTabId/__MODULE__" target="selectedTodo" posttype="string" calback="navTabAjaxMenu" rel=&#39;ids&#39; title="你确定要删除吗?" warn="请选择节点"><span>批量删除</span></a>
</li>
<table class="table" width="100%" layoutH="138">
    <thead>
      <tr>
        <th width="10"><input type="checkbox" class="checkboxCtrl" group="ids" /></th>
        <th width="60">编号</th>
      </tr>
    </thead>
    <tbody>
    <volist id="vo" name="list">
      <tr>
        <td><input name="ids" type="checkbox" value="{$vo.id}"> </td>
        <td>{$vo[&#39;id&#39;]}</td>
      </tr>
    </volist>
</table>
Copy after login

php:

public function deleteSelected() {
    //删除指定记录
    $name = $this->getActionName();
    $model = D($name);
    if (!empty($model)) {
      $pk = $model->getPk();
      $ids = $_REQUEST[&#39;ids&#39;];
      if (!empty($ids)) {
        $condition = array($pk => array(&#39;in&#39;, explode(&#39;,&#39;, $ids)));
        if (false !== $model->where($condition)->delete()) {
          $sql = $model->_sql();
          $this->success("删除成功!");
        } else {
          $this->error(&#39;删除失败!&#39;);
        }
      } else {
        $this->error(&#39;非法操作&#39;);
      }
    }
}
Copy after login

The principle is that you can pass an array when submitting a web form. For example:

<input type="text" name="firstname">
<input type="text" name="lastname">
<input type="text" name="email">
<input type="text" name="address">
<input type="text" name="tree[tree1][fruit]">
<input type="text" name="tree[tree1][height]">
<input type="text" name="tree[tree2][fruit]">
<input type="text" name="tree[tree2][height]">
<input type="text" name="tree[tree3][fruit]">
<input type="text" name="tree[tree3][height]">
Copy after login

Then what is passed is:

$_POST[] = array(
  &#39;firstname&#39;=>&#39;value&#39;,
  &#39;lastname&#39;=>&#39;value&#39;,
  &#39;email&#39;=>&#39;value&#39;,
  &#39;address&#39;=>&#39;value&#39;,
  &#39;tree&#39; => array(
    &#39;tree1&#39;=>array(
      &#39;fruit&#39;=>&#39;value&#39;,
      &#39;height&#39;=>&#39;value&#39;
    ),
    &#39;tree2&#39;=>array(
      &#39;fruit&#39;=>&#39;value&#39;,
      &#39;height&#39;=>&#39;value&#39;
    ),
    &#39;tree3&#39;=>array(
      &#39;fruit&#39;=>&#39;value&#39;,
      &#39;height&#39;=>&#39;value&#39;
    )
  )
)
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Based on Thinkphp and jquery, realize the function of ajax multi-selection, invert selection and delete data

About thinkphp Framework to implement deletion and batch deletion analysis

Use ThinkPHP framework to implement user information query and update and delete functions

The above is the detailed content of About how thinkPHP implements batch deletion. 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