0
如果找不到結果,我需要一些幫助在搜索框下方的頁面上彈出「無結果」消息。任何援助將不勝感激。當搜索沒有結果時添加「無結果」消息
目前代碼:
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
<form action="" method="post">
Search: <input type="text" placeholder="Enter Address" name="term" /><br />
<br />
<button class="ladda-button btn btn-primary" data-style="zoom-in">Submit
</button>
</form>
<?php
if (!empty($_REQUEST['term']))
{
$term = mysql_real_escape_string($_REQUEST['term']);
$sql = "SELECT * FROM triadlocations WHERE address LIKE '%".$term."%'";
$r_query = mysql_query($sql);
while ($row = mysql_fetch_array($r_query))
{
echo '<br /><br /> Location ID: ' .$row['locationid'];
echo '<br /> Address: ' .$row['address'];
echo '<br /> City: '.$row['city'];
echo '<br /> State: '.$row['state'];
echo '<br /> Zip: '.$row['zip'];
}
}
?>
</body>
</html>
許多簡單的解決方案存在,如添加初始化爲假的變量,並將其設置在真正的同時,事後檢查,或把所有行陣列中的第一和檢查,如果數組爲空,否則環..等等 –