Single-Condition query PHP

Source: Internet
Author: User

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

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.