PHP Bulk Delete data reduce programmer Stress _php Tutorial

Source: Internet
Author: User

First, in the article List page (list.php), the multi-select basket is named: "$del _id[]", the value is the article ID number. For example (list.php):

  1. < form name = ' Del_form ' action = ' del.php '
    method=' post '>
  2. < ? PHP
  3. $ result = mysql_query (' SELECT * from News ');
  4. While ($rs=mysql_fetch_array($result)) {
  5. ?>
  6. < input name=' del_id[] ' type =' checkbox '
    ID=' del_id[] ' value=' <? = $rs [id] ?> ' />
  7. < ? = $rs [title] ?>
  8. < ? PHP
  9. }
  10. ?>
  11. < /form >
  12. 2. Processing page (del.php):
  13. < ? PHP
  14. if ($del _id!= ") {
  15. $ Del_num = Count ($del _id);
  16. For ($i=0; $i< $del _num; $i + +) {
  17. mysql_query (' Delete from news where
    ID=' $del _id[$i] ');
  18. }
  19. Echo ('< script type=' text/ JavaScript '>
    alert (' Delete succeeded! '); History.back (); < /script > ');
  20. }else{
  21. Echo ('< script type=' text/javascript ') >
    alert (' Please select item first! '); History.back (); < /script > ');
  22. }
  23. ?>

1.PHP Bulk Delete Data first introduces jquery script library

 
  
  
  1. <scriptlanguage=' JavaScript '
    type = ' Text/javascript '
    src = ' Http://jqueryjs.googlecode.
    Com/files/jquery-1.3.2.min.js '>
  2. < /script >

Add the following code

 
 
  1. < script language=' JavaScript '
    type = ' Text/javascript ' >
  2. $ (document). Ready (function ()
  3. {
  4. $ (' input[id=' del '] '). Click (function ()
  5. {
  6. var Del_arry = '' ;
  7. $ (' input[name=' del_id[] '][checked] ')
    . each (function () {
  8. Del_arry Del_arry =del_arry+$ (This). Val () + ', ';
  9. });
  10. if (del_arry!= ")
  11. {
  12. $.post (' com_del.php ', {value: ' +
    del_arry+ '}, function (data) {
  13. if (data==1) {
  14. Window.location.reload ();
  15. Alert (' Delete succeeded! ');
  16. }else if (data==2) {
  17. Alert (' Delete failed! ');
  18. }
  19. });
  20. }
  21. });
  22. });
  23. < /script >

2.com_shen.php(The following sections can be played on their own, using your own database connection and processing methods)

 
 
  1. < ? PHP
  2. Include '. /cyr/inc/conn.php ';
  3. Include '. /cyr/inc/page.class.php ';
  4. $ Conn = New DB ();
  5. $conn- > Connection ();
  6. $ Array = $_post[' value '];
  7. Puts an array of the selected values into the $array array
  8. $ Array = Split (', ', $array);
  9. if (!empty ($array)) {
  10. $ Del_num = Count ($array);
  11. For ($II=0; $ii< $del _num; $ii + +) {
  12. $conn- > Str = ' Update yj_comment set
    co_shenhe=1 where id= '. $array [$ii];
  13. $conn- > GetResult ();
  14. }
  15. echo $ string = 1 ;
  16. }else{
  17. echo $ string = 2 ;
  18. }
  19. $conn- > colseconnection ();
  20. ?>

The above is the PHP bulk delete data related implementation method.


http://www.bkjia.com/PHPjc/445963.html www.bkjia.com true http://www.bkjia.com/PHPjc/445963.html techarticle first, in the article List page (list.php), the multi-select basket is named: $del _id[], the value is the article ID number. For example (list.php): Form name = ' del_form ' action = ' del.php ' method = ' post '? PHP $ re ...

  • Related Article

    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.