You are here:  » Expanding Results

Support Forum



Expanding Results

Submitted by crounauer on Fri, 2007-11-16 15:21 in

Hi David,

How would I go about showing a limited number of results from a query but then giving the user the option of expanding the results to show all.

For example, a user searches for washing machines and potentially 1000 results are available. Only 5 of those results should be shown, unless the user clicks on a link to show all the results.

I suppose like an expanding menu!

Thanks,
Simon

Submitted by support on Fri, 2007-11-16 15:32

Hi Simon,

The easiest way to do this would be to add a hidden field to the search form, for example "limit", and set that to the number of items you want returned in the first search. To add this, edit html/searchform.php and add the following code, before the closing form tag...

<input type='hidden' name='limit' value='5' />

Then, in search.php, look for the following code (line 89 in the distribution):

$sql .= " LIMIT ".$offset.",".$config_resultsPerPage;

...and replace this with:

if (isset($_GET["limit"]))
{
  $sql .= " LIMIT ".intval($_GET["limit"]);
}
else
{
  $sql .= " LIMIT ".$offset.",".$config_resultsPerPage;
}

Now all you need is a way to get out of this and re-load to the full result. To do this, just link directly to search.php?q=QUERY, for example:

  if (isset($_GET["limit"]))
  {
    print "<a href='search.php?q=".urlencode($q)."'>Click here for ALL results...</a>";
  }

The obvious place to insert the above code would be immediately BEFORE the following line, near the bottom of search.php:

if (isset($navigation)) require("html/navigation.php");

Hope this helps!
Cheers,
David.

Submitted by crounauer on Fri, 2007-11-16 15:44

Hi David,

Thanks for your quick reply!

Is that how the brands etc. at the bottom of this page are expanded?

http://www.google.co.uk/products?q=hiking+boots&sampleq=1

Thanks,
Simon

Submitted by support on Fri, 2007-11-16 17:46

Hi Simon,

The Google page is expanding by refining the query rather than just opening up more search results...

Cheers,
David.