SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Vancouver, BC
    0 Post(s)
    0 Thread(s)

    Locating "<< prev" and "next >>" primary key values

    Hi all!

    This is a general problem that I've run into again and again over the years, but never found a good solution.

    I often need to display a webpage table of data, sortable by whatever column the user wants and whatever search value they entered. As a concrete example, right now I'm looking at a table of user accounts with the following columns: "first name", "last name", "account status", "last logged in". This it all stored in a single MySQL table. There's a search bar at the top where they can search by a specific string to limit the accounts displayed in the page. Very straightforward.

    Now, when the user clicks on the "Edit" link for each item, I want that page to have "<< previous" and "next >>" links that will link to the appropriate account, as determined by the current search & sort.

    So in other words, I want an (efficient!) MySQL query that you can pass the primary key ID of the current row and get back the one before it and the one after it. Seems like this should be easy, but I haven't been able to figure out a solution.

    Any idea? Thanks in advance!

    - Ben
    A.P. - free JS/PHP/MySQL random test data generator.
    Form Tools - free PHP/MySQL form processor.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Toronto, Canada
    58 Post(s)
    3 Thread(s) | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts