-2

I have a search box and the user should type a transaction number to match a specific record. I was wondering how you would code it if nothing was typed and if it doesn't match a record/doesn't exist. I want it to display No Results, something like that.

search page:

<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>
JacksonW
  • 3
  • 4

1 Answers1

0

In admin_srchRslt.php, when you determine that no results were found, use header() to redirect to your "no results" page:

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

A better approach may be to send users to the same page every time but to simply change the results section of the page. If you are using an MVC framework, simply update the 'results' block in your view with the message that no results were found. Otherwise, you could do something like:

if (empty($results)) // If the $results array contains no data
{
    echo "No results were found";
}
else 
{
    foreach ($results as $result)
    {
         // Display the result
    }
}
George Cummins
  • 28,485
  • 8
  • 71
  • 90
  • yes i'm a beginner and sorry but I do get it. i'm trying it out and experimenting. – JacksonW Jan 10 '15 at 13:45
  • Thank you George! I used the if statement then put header() inside. – JacksonW Jan 10 '15 at 13:51
  • @JacksonW I didn't try to say anything bad, we all were beginners and all met those issues. But I am still hesitate if you've got an idea of "determine that no results were found". When you just wrote " I used the if statement then put header() inside.". could you show what IF condition is there? beleive me, I am really trying to help, not to argue and you are very welcome if any question. – Alex Jan 10 '15 at 15:33
  • @KimAlexander ok sorry I misunderstood you and took your comment negatively. It's ok now.I didn't post the php code in the question because it's too long dreamweaver auto coded that.i was in a hurry.my bad.It's great that George got what i meant with few details. I appreciate your help – JacksonW Jan 11 '15 at 05:38