Results 1 to 5 of 5

Thread: [RESOLVED] links to previous and next record

  1. #1

    Thread Starter
    Lively Member sridharao's Avatar
    Join Date
    Feb 2007
    Posts
    106

    Resolved [RESOLVED] links to previous and next record

    A very common issue, but I couldn't find solution. Please help!

    I have a table with an auto_increment id. Since records get deleted, the id number is not continuous or even sorted. I need to display contents of each record one at a time in a page with links to next and previous record at the bottom.

    How do I do this?
    Save trees, avoid plastics, say no to zoo, go veg, recycle as much, live holistic

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: links to previous and next record

    How are you displaying the records on an html page or flash page? The reason I ask is when viewing the contents of a database in phpdev one record = one row in the database. All the available record will be visible.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: links to previous and next record

    Quote Originally Posted by sridharao View Post
    I have a table with an auto_increment id. Since records get deleted, the id number is not continuous or even sorted. I need to display contents of each record one at a time in a page with links to next and previous record at the bottom.

    How do I do this?
    Off the top of my head:
    There are two ways to do this.

    In the first case you have already selected a cross-section of records (perhaps even cached them into a view. Well done!) and thus you know all of the IDs when you display the list of records. When you enter a single record, pass the previous and next IDs as parameters.

    This is the most efficient method. However...

    In the second case (which will inevitably occur regardless of whether you code for the first case) you are displaying a single record and have no idea what the previous and next records are. In this case you need to execute two SELECT queries to find them. You also need to decide on a sort column and order. If the records are naturally ordered by date, you can get "Newer" and "Older" IDs this way (where ? is the date of the current record):
    Code:
    # Newer
    select id from records where date>? order by date asc limit 1
    
    # Older
    select id from records where date<? order by date desc limit 1
    (There may be some way of doing it in one query, but I can't think of it right now.)



    Quote Originally Posted by Nightwalker83 View Post
    How are you displaying the records on an html page or flash page? The reason I ask is when viewing the contents of a database in phpdev one record = one row in the database. All the available record will be visible.
    I have no idea what bearing nor relevance this has to the question asked.

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: links to previous and next record

    Quote Originally Posted by penagate View Post
    I have no idea what bearing nor relevance this has to the question asked.
    I was thinking it being called from the actual html/flash page!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5

    Thread Starter
    Lively Member sridharao's Avatar
    Join Date
    Feb 2007
    Posts
    106

    Resolved Re: links to previous and next record

    I solved the issue by using the next and previous id's in the links.
    Save trees, avoid plastics, say no to zoo, go veg, recycle as much, live holistic

Posting Permissions

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



Click Here to Expand Forum to Full Width