php多關鍵字查詢

來源:互聯網
上載者:User

標籤:localhost   oct   nbsp   ima   idt   for   src   charset   att   

  php單一關鍵字查詢

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 tdansitional//EN" "http://www.w3.org/td/xhtml1/DTD/xhtml1-tdansitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title></head><body><h1>查詢頁面</h1><?php$db = new MySQLi("localhost","root","","12345");$tj = " 1=1 "; //條件預設恒成立$name = "";if(!empty($_POST["name"])){$name = $_POST["name"];$tj = " name like ‘%{$name}%‘ ";}?><form action="test.php" method="post"><div>請輸入名稱:<input type="text" name="name" /> <input type="submit" value="查詢" /></div></form><br><table width="100%" border="1" cellpadding="0" cellspacing="0"><tr>        <td>代號</td>        <td>名稱</td>        <td>系列</td>        <td>時間</td>        <td>油耗</td>        <td>功率</td>    </tr>    <?php$sql = "select * from car where {$tj}";echo $sql;$result = $db->query($sql);$attr = $result->fetch_all();foreach($attr as $v){$str = str_replace($name,"<mark>{$name}</mark>",$v[1]);echo "<tr>        <td>{$v[0]}</td>        <td>{$str}</td>        <td>{$v[2]}</td>        <td>{$v[3]}</td>        <td>{$v[4]}</td>        <td>{$v[5]}</td>    </tr>";}?></table></body></html>

 

 

結果:

 

關鍵字尋找“325”:

 

 

多條件查詢

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 tdansitional//EN" "http://www.w3.org/td/xhtml1/DTD/xhtml1-tdansitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title></head><body><h1>查詢頁面</h1><?php$db = new MySQLi("localhost","root","","12345");$tj1 = " 1=1 ";$tj2 = " 1=1 ";$name = "";if(!empty($_POST["name"])){$name = $_POST["name"];$tj1 = " name like ‘%{$name}%‘ ";}if(!empty($_POST["brand"])){$brand = $_POST["brand"];$tj2 = " brand = ‘{$brand}‘ ";}?><form action="main.php" method="post"><div>請輸入名稱:<input type="text" name="name" value="<?php echo $name ?>" /> 請輸入系列代號:<input type="text" name="brand" /><input type="submit" value="查詢" /></div></form><br><table width="100%" border="1" cellpadding="0" cellspacing="0"><tr>        <td>代號</td>        <td>名稱</td>        <td>系列</td>        <td>時間</td>        <td>油耗</td>        <td>功率</td>    </tr>    <?php$sql = "select * from car where {$tj1} and {$tj2}";echo $sql;$result = $db->query($sql);$attr = $result->fetch_all();if(count($attr)>0){foreach($attr as $v){$str = str_replace($name,"<mark>{$name}</mark>",$v[1]);echo "<tr><td>{$v[0]}</td><td>{$str}</td><td>{$v[2]}</td><td>{$v[3]}</td><td>{$v[4]}</td><td>{$v[5]}</td></tr>";}}else{echo "<script>alert(‘沒有查到資料‘);</script>";}?></table></body></html>

  

 

結果:

 

查詢關鍵字“奧迪”,代號為“b002”的結果:

 

php多關鍵字查詢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.