Skip to main content
Inspiring
September 24, 2008
Answered

Empty search results message shows up on page load

  • September 24, 2008
  • 2 replies
  • 578 views
******************
if ($totalRows_rs_searchresults == 0)
{ // Show if recordset empty ?>
<div align="center" class="body">Sorry your search returned no results, please try again</div>
******************

That works fine but obviously it shows up when the page is first loaded as the number of search results is zero. So how do I get that message to NOT show up until the form has been submitted for the first time?

Cheers

Dave


This topic has been closed for replies.
Correct answer Newsgroup_User
davecheet wrote:
> ******************
> if ($totalRows_rs_searchresults == 0)
> { // Show if recordset empty ?>
> <div align="center" class="body">Sorry your search returned no results, please
> try again</div>
> ******************
>
> That works fine but obviously it shows up when the page is first loaded as the
> number of search results is zero. So how do I get that message to NOT show up
> until the form has been submitted for the first time?

If you're using the GET method to submit the search form, amend the
conditional statement like this:

if (isset($_GET['search'])) && $totalRows_rs_searchresults == 0)

Change the value of 'search' to the name of the field being used to
filter the results. If you're using the POST method, use $_POST instead
of $_GET.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

2 replies

davecheetAuthor
Inspiring
September 24, 2008
That worked perfectly thanks David. I had to delete one of your brackets though.
if (isset($_POST['search'])) && $totalRows_rs_searchresults == 0)
became
if (isset($_POST['search']) && $totalRows_rs_searchresults == 0)

Thanks again for your help.

Cheers

Dave
Newsgroup_UserCorrect answer
Inspiring
September 24, 2008
davecheet wrote:
> ******************
> if ($totalRows_rs_searchresults == 0)
> { // Show if recordset empty ?>
> <div align="center" class="body">Sorry your search returned no results, please
> try again</div>
> ******************
>
> That works fine but obviously it shows up when the page is first loaded as the
> number of search results is zero. So how do I get that message to NOT show up
> until the form has been submitted for the first time?

If you're using the GET method to submit the search form, amend the
conditional statement like this:

if (isset($_GET['search'])) && $totalRows_rs_searchresults == 0)

Change the value of 'search' to the name of the field being used to
filter the results. If you're using the POST method, use $_POST instead
of $_GET.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/