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 ):
- < FormName = 'Del _ form' action = 'Del. php'
Method = 'post'>
- <? Php
- $ Result = mysql_query ('select * from news ');
- While ($ rs = mysql_fetch_array ($ result )){
- ?>
- < InputName = 'Del _ id [] 'type = 'checkbox'
Id = 'Del _ id [] 'value = '<? = $ Rs [id]?> '/>
- <? = $ Rs [title]?>
- <? Php
- }
- ?>
- </Form>
- 2. processing page (del. php ):
- <? Php
- If ($ del_id! = ''){
- $ Del_num = count ($ del_id );
- For ($ I = 0; $ I<$ Del_num; $ I ++ ){
- Mysql_query ('delete from news where
Id = '$ del_id [$ I] '');
- }
- Echo ('< ScriptType = 'text/javascript'>
Alert ('deleted successfully! '); History. back ();</Script>');
- } Else {
- Echo ('< ScriptType = 'text/javascript'>
Alert ('select a project first! '); History. back ();</Script>');
- }
- ?>
1. PHP batch data deletion first introduces the jquery Script Library
- < script language='JavaScript'
type='text/javascript'
src='http://jqueryjs.googlecode.
com/files/jquery-1.3.2.min.js'>
- < /script>
Add the following code
- <Script language = 'javascript'
Type = 'text/javascript '>
- $ (Document). ready (function ()
- {
- $ ('Input [id = 'del'] '). click (function ()
- {
- Var del_arry = '';
- $ ('Input [name = 'Del _ id [] '] [checked]')
. Each (function (){
- Del_arrydel_arry = del_arry + $ (this). val () + ',';
- });
- If (del_arry! = '')
- {
- $. Post ('com _ del. php', {value: ''+
Del_arry + ''}, function (data ){
- If (data = 1 ){
- Window. location. reload ();
- Alert ('deleted successfully! ');
- } Else if (data = 2 ){
- Alert ('deletion failed! ');
- }
- });
- }
- });
- });
- </Script>
2.com _ shen. php(The following sections can be used by yourself to connect to and handle your own database)
- <? Php
- Include '../cyr/inc/conn. php ';
- Include '../cyr/inc/page. class. php ';
- $ Conn = new DB ();
- $ Conn-> Connection ();
- $ Array = $ _ POST ['value'];
- // Put the array composed of the selected values into the $ array
- $ Array = split (',', $ array );
- If (! Empty ($ array )){
- $ Del_num = count ($ array );
- For ($ ii = 0; $ ii <$ del_num; $ ii ++ ){
- $ Conn-> str = 'update yj_comment set
Co_shenhe = 1 where id = '. $ array [$ ii];
- $ Conn-> getResult ();
- }
- Echo $ string = 1;
- } Else {
- Echo $ string = 2;
- }
- $ Conn-> ColseConnection ();
- ?>
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...