Home Backend Development PHP Tutorial About how thinkPHP implements batch deletion

About how thinkPHP implements batch deletion

Jun 08, 2018 pm 02:11 PM
thinkphp batch deletion

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to delete Weibo posts in batches? -How to cancel your Weibo account? How to delete Weibo posts in batches? -How to cancel your Weibo account? Mar 18, 2024 pm 03:00 PM

How to delete Weibo posts in batches? To delete Weibo posts in batches, you can follow the steps below: Log in to your Weibo account and visit your personal center in the browser. Click More under Admin Center or Apps and select My Apps. Search and find the batch deletion Weibo tool in the App Market. Using this tool, you can choose to delete some Weibo posts or delete them all at once. After completing the deletion operation, if you need to restore the deleted content within 24 hours, you can use the member privilege &quot;Regret Medicine&quot;. This function cannot be used after 24 hours. In addition, there are other methods to achieve batch deletion of Weibo, such as using specific browser plug-ins, but these methods may not be officially supported and may pose security risks. Therefore, it is recommended to give priority to the official

Various ways to implement batch deletion operations in MyBatis Various ways to implement batch deletion operations in MyBatis Feb 19, 2024 pm 07:31 PM

Several ways to implement batch deletion statements in MyBatis require specific code examples. In recent years, due to the increasing amount of data, batch operations have become an important part of database operations. In actual development, we often need to delete records in the database in batches. This article will focus on several ways to implement batch delete statements in MyBatis and provide corresponding code examples. Use the foreach tag to implement batch deletion. MyBatis provides the foreach tag, which can easily traverse a set.

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Detailed explanation of how to use MyBatis batch delete statements Detailed explanation of how to use MyBatis batch delete statements Feb 20, 2024 am 08:31 AM

Detailed explanation of how to use MyBatis batch delete statements requires specific code examples. Introduction: MyBatis is an excellent persistence layer framework that provides rich SQL operation functions. In actual project development, we often encounter situations where data needs to be deleted in batches. This article will introduce in detail how to use MyBatis batch delete statements, and attach specific code examples. Usage scenario: When deleting a large amount of data in the database, it is inefficient to execute the delete statements one by one. At this point, you can use the batch deletion function of MyBatis

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

See all articles