views:

42

answers:

1

Hi There,

I am struggling alot with some PHP I am needing to implement a next and previous link, basically I have a search function on my site, that returns multiple results and click on a result navigates to that results page, I want to then be able to click next on that page, and be taken to the next result in the sequence that was returned by the users original search? Is this possible, and how? I have no clue.

+1  A: 

With pagination your search query will need to be able to return the results from x to y. So you can search for monkeys and return all results from 1 to 10, then 11 to 20 for the next page.

search( $term='monkey', $firstResult=0, $numberOfResults=10 );

Your results page should take the term, firstResult and numberOfResults as query string parameters. So if your first page looks like this:

search.php?term=monkey&firstResult=0&numberOfResults=10

You next link will look like this:

search.php?term=monkey&firstResult=11&numberOfResults=20

You can also use a predefined numberOfResults per page, so that you only need a $page parameter (e.g. search.php?term=monkey&page=1, search.php?term=monkey&page=2).

vfilby