May 21 Auto Search and Bulk Delete----PHP method

Source: Internet
Author: User

---restore content starts---

This is different from the previous implementation of the page in PHP query, reference AJAX implementation of bulk deletion and pop-up window display

Job Requirements:

The page displays the data code:

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >hover{Cursor:pointer;}</style>PHPinclude(".. /dbda.php "); $db=NewDbda (); $cx= ""; $value= ""; if(!Empty($_post["name"]))//the value is not empty    {        $name=$_post["Name"];//name of the name to take the input        $cx= "Where name like '%{$name}%‘";//query string        $value=$name; }><form action= "zhuym.php" method= "POST" ><div> Please enter name: <input type= "text" name= "name" value= "&LT;? PHP Echo$value?> "/>&nbsp; <input type= "Submit" value= "commit"/></div></form><br/><br/> <table width= "100%" Borde R= "1" cellpadding= "0" cellspacing= "0" > <tr> <td> code </td> <td> Auto name </td> <td& GT, Price </td> <td> fuel consumption </td> <td> power </td> <td> operation </td> </tr> &L t;?PHP$sql= "SELECT * from Car".$cx; $attr=$db->query ($sql);//query is a method        foreach($attr  as $v)    {        //Working with Strings        $RP= "<span style= ' background:red ' >{$value}</span> "; $str=Str_replace($value,$RP,$v[1]);//to replace the keyword, replace with, string                Echo"<tr> <td id= ' code ' ><input type= ' checkbox ' value= ' {$v[0]} ' class= ' XZ '/>{$v[0]}</td> <td>{$str}</td> <td>{$v[7]}</td> <td>{$v[4]}</td> <td>{$v[5]}</td> <td><span class= ' Chakan ' bs= ' {$v[0]} ' > View details </span></td> </tr>"; }    ?> <tr><td><input type= "checkbox" id= "All"/> Select &nbsp;&nbsp;<input type= "button" id= " Butt "value=" bulk Delete "/></td></tr> </table> </body>$ (document). Ready (function(e) {//All-selected buttons$ ("#all"). Click (function(){                varCK = $ (". XZ"); varXZ = $ (this) [0].checked; CK. Prop ("Checked",XZ); })                //Delete and bulk Delete$ ("#butt"). Click (function(){                varCK = $ (". XZ");  for(vari=0;i<ck.length;i++)        {            if(Ck.eq (i). Prop ("checked")))            {                varCode =ck.eq (i).Val (); $.Ajax ({URL: "Chulieasy.php",Data: {code:code,type:1},DataType: "TEXT",type: "POST",Success:function(data) {//alert (data);                                                if(Data.Trim() = = "OK") {window. location.href= "Zhuym.php"; }                        Else{alert ("Delete Failed");                }                        }                    }); }                        }            })                //pop -up window$ ('. Chakan '). Click (function(){                varCode = $ (This). attr ("BS"); $.Ajax ({URL: "Chulieasy.php",DataType: "JSON",Data: {Code:code,type:2},type: "POST",Success:function(data) {//alert (data);str1= "";  for(KeyIn data) {str1+ = "<span>" +data[Key][1]+ "</span>&nbsp;&nbsp;"; STR1+ = "<span>" +data[Key][2]+ "</span>&nbsp;&nbsp;"; STR1+ = "<span>" +data[Key][3]+ "</span>&nbsp;&nbsp;"; STR1+ = "<span>" +data[Key][4]+ "</span>";            }                }            }); varhtml = "<div style= ' color:red ' >" +str1+ "</div>"; varbutton = "<input type= ' button ' value= ' OK '/><input type= ' button ' value= ' Cancel '/> '; varWin =NewWindow ({width: 700,//widthHEIGHT:500,//HeightTitle: ' Pop-up window ',//titleContent:html,//contentIsmask:false,//whether or not to maskButtons:button,//ButtonIsdrag:true,                                }); })        });</script>
View Code

Processing pages, but merging them together chulieasy.php

<?PHPinclude(".. /dbda.php ");$db=NewDbda ();$type=$_post["Type"];Switch($type){     Case1:$code=$_post["Code"]; $sql= "Delete from car where code = ' {$code}‘"; $result=$db->query ($sql, 1);//true if success Returns or false        if($result)        {            Echo"OK"; }        Else        {            Echo"NO"; }         Break;  Case2:$code=$_post["Code"]; $sql= "Select Code,name,price,oil,powers from car where Code = ' {$code}‘ "; $attr=$db->query ($sql); EchoJson_encode ($attr);  Break; default:Echo"";}
View Code

It's a little bit easier relative to Ajax.

---restore content ends---

May 21 Auto Search and Bulk Delete----PHP method

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.