Batch delete based on ThinkPHP ,. Batch deletion based on ThinkPHP. This article analyzes code instances for batch deletion based on ThinkPHP and shares them with you for your reference. The details are as follows, first, batch deletion is implemented based on ThinkPHP,
This article analyzes code instances for batch deletion based on ThinkPHP and shares them with you for your reference. The details are as follows:
Not to mention nonsense. First, go:
HTML layout (based on bootstrap)
Delete the message list
|
Id |
Name |
Email |
Content |
Date and time |
Operation |
JS script processing (using ajax technology)
First, check whether there is any selected value. if there is no selected value, the prompt is displayed. If yes, it is passed to the server for processing.
/* Batch delete * // select all $ ('. all '). click (function () {if ($ (this ). is (': checked') {$ (': checkbox '). attr ('checked', 'checked');} else {$ (': checkbox '). removeAttr ('checked') ;}}); // delete operation $ ('# discard '). click (function () {if ($ (': checked '). size ()> 0) {layer. confirm ('are you sure you want to delete it? ', {Btn: [' OK ', 'cancel'], // Button shade: false // do not display mask}, 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 ('deleted! ', {Time: 1000}) ;}) ;}else {layer. alert (' no choice! ');}});
PHP code:
Obtain the submitted data, obtain the value of each id cyclically, and then perform the delete operation.
Public function discard () {$ contact = M ('Contact '); $ deleteArr = I ('post. data'); for ($ I = 0; $ I
Delete ($ deleteArr [$ I] ['value']);} $ this-> ajaxReturn (array ('message' => 'deleted successfully! '));}
The above is the key code for implementing batch deletion in ThinkPHP. I hope it will be helpful for your learning.
Articles you may be interested in:
- Php batch delete data
- Batch delete SQL statements in PHP
- PHP batch data deletion method analysis
- Code for batch deleting data tables with the same prefix in Mysql in php
- PHP code example for batch delete, clear UTF-8 file BOM header
- Code instances for batch data deletion using ThinkPHP
- Php batch deletes tables with the specified prefix in the database. prefix _ is used as an example.
- Simple implementation of batch deletion of cookies in php
Examples in this article analyze code instances for batch deletion based on ThinkPHP and share them with you for your reference. The details are as follows...