PHP: switch through user details based on userid in url with previous and next buttons

peps03
peps03 used Ask the Experts™
on
Hi,

On my first page i have a list of users, say 7. when one is clicked on you get to see his details.
Now, the userid for which the information is needed is sent via the url: ?userid=1.
(but only of 1 user)

What i'm trying to do is, when on the detail page of a user, create a previous and a next button to switch between the detail pages without having to go back to the overview page.

how do i pass the correct userids to the links of the previous and next buttons?

should i grab the userid's on every page from the db and assign the one before the current to the previous button and the following id to the next button? (if so, how do i get the previous and following userids from a string?)

or is there a better method?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Assuming the ID is auto_increment and since you didn't specify a DBMS I'll assume you're using MySQL as such you could get the previous like this:
SELECT id FROM users WHERE id < $id ORDER  BY id DESC LIMIT 1

Open in new window

Where $id is the id of the currently viewed user. Then do the opposite for the next user:
SELECT id FROM users WHERE id > $id ORDER BY id ASC LIMIT 1

Open in new window

Hope that helps.

Author

Commented:
Thanks!!
Works like a charm!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial