This article mainly introduces code instances for batch deletion based on ThinkPHP, which has some reference value, if you are interested, you can refer to the examples in this article to analyze code instances for batch deletion based on ThinkPHP and share 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.