Batch delete based on ThinkPHP

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.