1. Add conditions to the multi-conditional query
PHP$tiaojian 1= "1=1";$tiaojian 2= "1=1";$title="";//To be able to take this variable in the following foreach, define it outside. $author="";if(!Empty($_post[' title '])){ $title=$_post[' title ']; $tiaojian 1= "title like '%{$title}%‘"; } /*else {echo "<script> alert (' Please enter ');</script>"; If the input is empty, you can do a pop-up window to prompt}*/if(!Empty($_post[' Author '])){ $author=$_post[' Author ']; $tiaojian 2= "Author like '%{$author}%‘"; }?>
2. Create a form
$title,?> ">$author?>" > $title
3. Create a display area
<form action= "piliangshanchu.php" method= "POST" ><table width= "95%" border= "1" cellpadding= "0" cellspacing= " 0 "align=" center "><tr><td><input type=" checkbox "onclick=" Quanxuan (This) "> title </td> <! --Add a check box to the title bar--><td> author </td><td> source </td><td> content </td><td> Publish time </td ><td> Delete </td><td> modify </td></tr><?PHP$db=NewMysqli ("localhost", "root", "123", "Test1");Mysqli_connect_error()?" Connection failed ":" ";$sql= "SELECT * from news where {$tiaojian 1} and {$tiaojian 2}";Echo $sql;//OUTPUT statement See results$result=$db->query ($sql);$attr=$result-Fetch_all ();foreach($attr as $v){ /*$str =str_replace ($title, "<mark>{$title}</mark>", $v [1]); Str_replace to replace, add mark tags, special display of keywords*/ $str=Str_replace($title, "<span style= ' color:red; ' >{$title}</span> ",$v[1]);//You can also change the color of a span by adding <span> tags Echo"<tr><td><input type= ' checkbox ' value= ' {$v[0]} 'name= ' sc[] 'class= ' Xuanzhong '/>{$str}</td><td>{$v[2]} </td><td>{$v[3]} </td><td>{$v[4]} </td><td>{$v[5]} </td><td><a href= ' shanchu.php?ids={$v[0]} ' Onclick=\ "return confirm (' confirm delete ') \" > Delete </a></td><td><a href= ' xiugai.php?ids={$v[0]} ' > Modify </a></td></tr> "; Focus: When making check box multiple selection, the value of name will be received with sc[] array}></table><div><input type= "Submit" value= "Bulk Delete" ></div></form>
4. Through the status of the check box in the title bar, make multiple selections for the following checkboxes, using JS
<script type= "Text/javascript" >functionQuanxuan (a) {varCk=document.getelementsbyclassname ("Xuanzhong"); for(vari=0;i<ck.length;i++) { if(a.checked)//determine the selected state of a{Ck[i]. SetAttribute ("Checked", "checked");//Setting Add Properties } Else{Ck[i]. RemoveAttribute ("checked");//Removing properties from } } }</script>
5. Processing interface for bulk deletion
<?PHPif(!Empty($_post[' SC '])//Through the check box above the selected value, extract it is the form of the array {$attr=$_post[' SC ']; Put in an array$db=NewMysqli ("localhost", "root", "123", "Test1");Mysqli_connect_error()?" Connection failed ":" ";/*foreach ($attr as $v) {$sql = "Delete from news where ids= ' {$v} '", if ($result = $db->query ($sql)) {Header ("Location: Main.php "); } else {echo "delete failed"; }}*/$atr=implode("‘,‘",$attr); By using the Implode function, the array is combined into a string that forms the conditional statement conditional statement in (', ', ' ', ', ') for the following SQL statement$sql= "Delete from news where IDs in (' {$atr}‘)"; if($result=$db->query ($sql)){ Header("location:main.php"); } Else { Echo"Delete Failed"; }}
PHP section---Multi-conditional query of data, bulk delete