如果找不到结果,我需要一些帮助,在搜索框下方的页面上添加“无结果”消息。任何援助将不胜感激。
当前代码:
<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>
答案 0 :(得分:0)
检查while
循环前的结果数。如果没有结果,请打印消息。
if (mysql_num_rows($r_query)) {
while ($row = mysql_fetch_array($r_query)){
...
}
} else {
echo "No Results";
}