Batch deletion of PHP Data reduces programmer pressure _ PHP Tutorial

Source: Internet
Author: User
Batch deletion of PHP Data reduces programmer pressure. First, on the article list page (list. php), name the multiple selection baskets $ del_id [] and set the value to the article ID number. For example (list. php): formnamedel_formactiondel.phpmethodpost? Php $ re

First, on the article list page (list. php), name the multiple selection baskets "$ del_id []" and set the value to the article ID. For example (list. php ):

  1. < FormName = '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. < InputName = '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 ('< ScriptType = 'text/javascript'>
    Alert ('deleted successfully! '); History. back ();</Script>');
  20. } Else {
  21. Echo ('< ScriptType = 'text/javascript'>
    Alert ('select a project first! '); History. back ();</Script>');
  22. }
  23. ?>

1. PHP batch data deletion first introduces the jquery Script Library

 
 
  1. < script language='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_arrydel_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 ('deleted successfully! ');
  16. } Else if (data = 2 ){
  17. Alert ('deletion failed! ');
  18. }
  19. });
  20. }
  21. });
  22. });
  23. </Script>

2.com _ shen. php(The following sections can be used by yourself to connect to and handle your own database)

 
 
  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. // Put the array composed of the selected values into the $ 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 how PHP batch deletes data.


(List. php), name the multiple selection baskets: $ del_id [], and the value is the article ID. For example, (list. php): form name = 'Del _ form' action = 'Del. php' method = 'post '? Php $ re...

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.