"Bob Bedford" <be******@YouKnowWhatToDoHerehotmail.com> wrote in message
news:41**********************@news.sunrise.ch...
I want 10 results (not necessarely the first 10) in the actual page. In
the other page, I need only 1 result BUT I've to know previous and next
record.
Takes this example. I'm in the search page. The result gives 150 results.
I only show 10 results/page.
Now, I click on an element (one of the result). From there I'd like to
click on "next item" or "previous item".
For this I've to know each element of the query's result. But how to do
previous and next ??? now I've executed the query, then I put each element
ID in an array. When I go in element page, I have the array, so clicking
on previous I've the previous ID, clicking on next, I've the next ID. Then I
show the element with the new ID.
The problem is that If I click 12 times on "next", I've to know that
clicking on "return" button (not the previous of the browser), the page
has changed. I should be in page 2 now.
How to fill the array then show only 10 results ? What should I do ?
Hmmm. Tricky. In order to determine what the previous and next item are, you
will need to perform the original query. There's really no way around that.
Storing data in session variable is always rather dicey in these kinds of
scenarios.
What I would do is in the URL to the element page, put in the variables that
we'd need to reconstruct the search query, the id of the element, and the
position of that element within the result set. In the element page itself,
perform the same query, but use a window of 3--one ahead of the position of
the element and one behind. To make sure that the position of the element
within the result set hasn't since changed, compare the id of the middle row
to the one from the URL. If they don't match, retrieve the entire data set
to look for the correct 3 rows. For the "prev" and "next" links, go the same
thing.
The drawback is that running the query is slower than getting the data of
the element using a primary key. On the other hand, because you're running
the same query over and over, the database server should be smart enough to
cache that data set.