Main Page
1<form action= "main.php" method= "POST" >2<div> Name:3<input type= "text" name= "XM"/>4<input type= "Submit" value= "Query"/>5</div>6</form>7<br/>8 9<form action= "piliangshanchu.php" method= "POST" >Ten<table width= "100%" border= "1" cellpadding= "0" cellspacing= "0" > One<tr> A<td><input type= "checkbox" onclick= "Quanxuan (This)"/> Code </td> -<td> name </td> -<td> Sex </td> the<td> ethnic </td> -<td> Birthdays </td> -<td> Operations </td> -</tr> + -<?PHP + A //first determine if there is a commit value at $XXM= ""; - $TJ= "1=1"; - if(!Empty($_post["XM"]) &&$_post["XM"]!= "") - { - $XXM=$_post["XM"]; - $TJ= "Name like '%{$XXM}%‘ "; in } - to //Connecting Objects + $db=NewMysqli ("localhost", "root", "123", "MyDB"); - //Write SQL statements the $sql= "SELECT * from Info where".$TJ; * Echo $sql; $ //Execute SQL statementPanax Notoginseng $result=$db->query ($sql); - //Read Data the $attr=$result-Fetch_all (); + A foreach($attr as $v) the { + Echo"<tr>"; - $ $sex=$v[2]? " Male ":" Female "; $ - //Query name family name based on name Family Code - $name= Nationname ($v[3]); the - //Replace keywordWuyi $newname=Str_replace($XXM, "<mark>{$XXM}</mark> ",$v[1]); the - 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= ' shanchu.php?c={$v[0]} ' Onclick=\ "return confirm (' OK to delete? ') \ ' > Delete </a><a href= ' xiugai.php?c={$v[0]} ' > Modify </a></td> "; Wu - /*foreach ($v as $v 1) About { $ echo "<td>{$v 1}</td>"; - }*/ - - Echo"</tr>"; A } + the //give a national code, return the name of the Nation - functionNationname ($code) $ { the //Connecting Objects the $db=NewMysqli ("localhost", "root", "123", "MyDB"); the //Write SQL statements the $sql= "SELECT name from Nation where Code= ' {$code}‘"; - //Execute SQL statement in $result=$db->query ($sql); the the $attr=$result-Fetch_row (); About the return $attr[0]; the } the +?> - the Bayi</table> the<a href= "add.php" ><input type= "button" value= "Add Data"/></a> the -<input type= "Submit" value= "bulk Delete" onclick= "return confirm (' OK delete ')"/> -</form> the the<script type= "Text/javascript" > the the functionQuanxuan (a) - { the //Find all of the check boxes below the varCK =document.getelementsbyclassname ("QX"); the 94 //Traverse all check boxes to set the selected state the for(vari=0;i<ck.length;i++) the { the if(A.checked)98 { AboutCk[i].setattribute ("Checked", "checked"); - }101 Else102 {103Ck[i].removeattribute ("Checked");104 } the }106 107 }108</script>
Delete Processing page
1<?PHP2 $attr=Array();3 if(!Empty($_post["SC"]))4 {5 $attr=$_post["SC"];6 }7 8 $db=NewMysqli ("localhost", "root", "123", "MyDB");9 Ten /*foreach ($attr as $v) One { A $sql = "Delete from info where code= ' {$v} '"; - - $db->query ($sql); the } - */ - - $str=implode("‘,‘",$attr); + - //echo $str; + A $sql= "Delete from info where code in (' {$str}‘)"; at $db->query ($sql); - -?>
PHP Bulk Delete