-2

我有一个搜索框,用户应该输入一个交易号来匹配特定的记录。我想知道如果没有输入任何内容并且它与记录不匹配/不存在,您将如何对其进行编码。我希望它显示无结果,类似的东西。

搜索页面:

<form action="admin_srchRslt.php" method="get">
  <center>
    <br/>Search Transaction No.<br/>
    <input name="search" type="text" id="search" />
    <input name="btnSearch" type="submit" id="btnSearch" value="Search" />
  </center>
</form>
4

1 回答 1

0

在 admin_srchRslt.php 中,当您确定没有找到结果时,使用header()重定向到您的“无结果”页面:

header("Location: /no_results.html");

更好的方法可能是每次都将用户发送到相同的页面,而只是简单地更改页面的结果部分。如果您使用的是 MVC 框架,只需使用未找到结果的消息更新视图中的“结果”块。否则,您可以执行以下操作:

if (empty($results)) // If the $results array contains no data
{
    echo "No results were found";
}
else 
{
    foreach ($results as $result)
    {
         // Display the result
    }
}
于 2015-01-10T13:17:02.153 回答