Page 1.php
<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >Please enter your name:<input type= "text" name= "name"/> <input type= "submit" value= "Query"/></div></form><br/>& Lt;table width= "100%" border= "1" cellpadding= "0" cellspacing= "0" ><tr> <td> code </td> <td> Name & lt;/td> <td> phone </td> <td> group </td></tr><?PHP//implement two logical//1. If there is no post data, check all//2. If there is post data, check the conditions according to$db=NewMysqli ("localhost", "root", "root", "dbname");/*if (post pass value) {SQL statement 1}else{SQL statement 2}*/$TJ= "1=1";//Default Condition$name= "";//the outside to write a default value, if not write, if not go if there will be no valueif(!Empty($_post)){ $name=$_post[' Name ']; $TJ= "Name like '%{$name}%‘ ";}//stitching conditions into an SQL statement$sql= "SELECT * from contacts where {$TJ}";//echo $sql;$result=$db->query ($sql); while($arr=$result-Fetch_row ()) { //Special display of keywords $str=Str_replace($name, "<mark>{$name}</mark> ",$arr[1]);//Find replacement//substr_replace ();//Specify Location substitution Echo"<tr> <td>{$arr[0]}</td> <td>{$str}</td> <td>{$arr[2]}</td> <td>{$arr[3]}</td></tr>";}?></table></body>
Single-Condition query PHP