PHP Data Access Bulk Delete (10261101)

Source: Internet
Author: User

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >Name:<input type= "text" Name= "XM"/><input type= "submit" value= "Query"/></div></form><br/> <form action= "1101morningpiliangshanchu.php" method= "POST" ><table width= "100%" border= "1" cellpadding= "0"        cellspacing= "0" > <tr> <td><input type= "checkbox" onclick= "Quanxuan (This)"/> Code </td>         <td> name </td> <td> gender </td> <td> National </td> <td> Birthday </td> <td> operation </td> </tr><?PHP//Query rule: When the user does not enter the case, the query is all the data//first to determine if there is no commit value/*simplify the pre-$xm= "", if (!empty ($_post["XM"))//empty (); Add a conditional judgment to prevent error {$XM = $_post["XM"]; }//simplified before $tj = ""; if ($XM = = "")//if there is no value, check all, without conditions, or give a constant set of conditions. If there is a value, look for {$TJ = "1=1";//Do not forget to add a space on both sides (convenient splicing SQL statement)}else{$TJ = "name like '%{$xm}% '";//Don't forget to add space on both sides, fuzzy query with like}/    /simplified after $tj = "1=1";//default constant Set if ($XM! = "") {$tj = "name like '%{$xm}% '"; }*///simplify and then one:$XXM= "";$TJ= "1=1";if(!Empty($_post["XM"]) &&$_post["XM"]! = "" ")//determine if XM is empty{    $XXM=$_post["XM"]; $TJ= "Name like '%{$_post[' XM ']} %‘ ";//You can add a single quotation mark to a variable}/*Simplified Two: $tj = "1=1", if (!empty ($_post["XM"))//Determine if XM is empty {if ($_post["XM"]! = ")//Determine if XM is an empty string {$tj =" NA        Me like '%{$xm}% ' "; }}*///Connecting Objects$db=NewMysqli ("localhost", "root", "Database Password", "1016");//Write SQL statements$sql= "SELECT * from Info where".$TJ;//(stitching the SQL statement, where the space behind is to prevent the concatenation of the statement error.) alone is because if you write a sentence, the user if nothing input, the value of the query is empty, this conflict with the query law that the user does not input anything, query all data)//Execute SQL statement $result=$db->query ($sql);//read the data and return a two-dimensional array$attr=$result-Fetch_all ();//foreach iterates through the array,foreach($attr  as $v)//$attr as $v take every decimal group inside the attr{    Echo"<tr>"; $sex=$v[2]? " Male ":" Female ";//Array v $v index Two, with the ternary operator, the front is a Boolean data, true display male, false display female 0 false,1 true//According to the National Code query national name can also use join query, but generally not recommended, because the number of queries It's too big.        /*$sname = "SELECT name from Nation where code = ' {$v [3]} '";    $rname = $db->query ($sname); $aname = $rname->fetch_row ();*/        $name= Nationname ($v[3]); //make keywords highlight <mark></mark>    /*simplified in the above $XXM = "";//the XXM variable is defined in the outer layer if (!empty ($_post["XM"))//And then determine if there is a commit value {$XXM = $_post["XM"];//have the value of the message to take X m}*/    //Replace keyword    $newname=Str_replace($XXM, "<mark>{$XXM}</mark> ",$v[1]);//find replacements, the first parameter: keywords, according to what to look for; the second keyword, the replacement of the content; the third argument: which string to replace, that is, the area to replace//check with the array to submit sc[], to the processing page, the array can be traversed    Echo"<td><input type= ' checkbox ' value= ' {$v[0]} ' Name= ' sc[] ' class= ' QX '/>{$v[0]} </td><td>{$newname}</td><td>{$sex}</td><td>{$name}</td><td>{$v[4]} </td><td><a href= ' 1028afternoonshanchu.php?c={$v[0]} ' > Delete </a> <a href= ' 1030morningxiugai.php?c={$v[0]} ' > Modify </a></td> "; //jump to another page and take a value the way it used to be is get, so we're going to simulate a get-pass method? c={$v [0]}//To add a delete function first let it click, one method is a button, the other is the <a> tag. Styles can be done casually, such as adding a nice div to the outside, plus a <a> tag inside.         /*the output of the two methods of foreach ($v as $v 1) {echo "<td>{$v 1}</td>"; }*/        Echo"</tr>";} //give a national code, return the name of the Nation    functionNationname ($code)    {        //Connecting Objects        $db=NewMysqli ("localhost", "root", "Database Password", "1016"); //Write SQL statements        $sql= "SELECT name from Nation where Code= ' {$code}‘"; //Execute SQL statement        $result=$db->query ($sql); $attr=$result-Fetch_row (); return $attr[0]; }></table><a href= "1028afternoonadd.php" ><input type= "button" value= "Add Data"/></a>< Input type= "submit" value= "bulk Delete" onclick= "return confirm (' OK to delete? ') "/></form><!--Bulk Delete ideas: Think of checkboxes and bulk delete buttons as a form--><script>functionQuanxuan (a) {//Find all of the check boxes below    varck = Document.getelementsbyclassname ("QX"); //not the document points out there is no hint, if you are afraid of mistakes can be here to define a variable and then point out and then copy over//Traverse all check boxes, set the selected state     for(vari=0;i<ck.length;i++)    {        if(A.checked) {            /*setAttribute ("Checked", "checked") Set properties ("First name"; "Value")*/Ck[i]. SetAttribute ("Checked", "checked"); }        Else        {            /*removeattribute ("Checked", "checked") Remove attribute ("First name"; "Value")*/Ck[i]. RemoveAttribute ("Checked", "" "); }    }}</script></body>1028afternoonmain.php

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >$_post[] is empty, you can also determine the variablewhether the $a is empty--><?PHP//empty (); Determine if the variable has no assignment or the value is an empty string, 0 so for example, if the query is empty, when the input 0 will be queried all//$a = "";//var_dump (empty ($a));// When the variable is 0 or "" The empty string is also true, will be 0 or "" as the null//isset judgment variable has not been defined, there is no setting, set the return to True, no set return false//$b =0;//var_dump (isset ($b)); Returns True when the variable is 0 or "", that is, no 0 or "" as an empty//is_null to determine whether it is empty, undefined$c=NULL;Var_dump(Is_null($c));//cannot determine a variable not defined//when the variable is undefined or defined but not assigned, that is, NULL returns TRUE when the variable is 0 or "" empty string returns False, that is, 0 or "" as empty?></body>1101morningceshi.php

<?PHP$attr=Array();//define an empty arrayif(!Empty($_post["SC"])){    $attr=$_post["SC"];}$db=NewMysqli ("localhost", "root", "Database Password", "1016"); //the above sentence was put outside to prevent the loop from being built once every time it was executed ./*before optimization (once per SQL statement) foreach ($attr as $v) {$sql = "Delete from info where code= ' {$v} '"; $db->query ($sql);}*///after optimization: Delete a set of data using the in Split string to return an array of explode array concatenation string implode//implode (); First argument: Delimiter second argument: array$str=implode("‘,‘",$attr);$sql= "Delete from info where code in (' {$str}‘)"; $db->query ($sql);Header:("location:1028afternoonmain.php");?>
1104piliangshanchu.php

PHP Data Access Bulk Delete (10261101)

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.