Design ideas and some key code for batch deletion of THINKPHP3.0

Source: Internet
Author: User
This example shows the customer information in the customer information table. After batch deletion, the user displays the page code sdel.html to dynamically obtain the user information: & lt; formaction & quot ;__ URL _/sdelete/& quot; method & quot; post...

In this example, the customer information of the customer information table is deleted. First, the user displays the page code sdel.html to dynamically obtain the user information:

  1.  
  2. Customer ID 
  3. Customer store name 
  4. Customer name 
  5. Customer phone number 
  6. Customer address 
  7. Select 
  8.  
  9.  
  10. {$ Khxx. id}
  11. {$ Khxx. name} 
  12. {$ Khxx. cname} 
  13. {$ Khxx. tel} 
  14. {$ Khxx. address} 
  15.  
  16. // Note that the user ID transmitted to the delete page is hidden.
  17.  
  18. {$ Page} 
  19.  

Delete method sdelete ()

  1. ? Function sdelete (){
  2.  
  3. $ User = M ('customer'); // instantiate the model
  4. If ($ data = $ user-> create () {// create a data object
  5. $ Data = array_pop ($ data); // Convert the obtained two-dimensional array to one-dimensional array.
  6. $ List = ""; // instantiate the parameter to be deleted
  7. $ Max = count ($ data)-1; // extract the array length to prepare a loop
  8. For ($ I = 0; $ I <= $ max; $ I ++) {// cyclically extract an array
  9. If ($ I! = $ Max) {// if it is not the last value of the array, a comma (,) is added. otherwise, no separator is added and a loop is introduced. $ List
  10. $ List = $ list. $ data [$ I]. ',';
  11. } Else {
  12. $ List = $ list. $ data [$ I];
  13. }
  14. }
  15. If ($ user-> where ('Id in ('. $ list. ')-> delete () {// delete a data record. SQL = delete * from customer where id in ($ list );
  16. $ This-> success ('deleted successfully ');
  17. } Else {
  18. $ This-> error ('deletion failed ');
  19. }
  20. } Else {
  21. $ This-> error ('verification failed ');
  22. }
  23. }

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.