SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    previous and next links

    Hi

    This is a beginners question I think.

    I have a table of news items - which are currently listed - each linked to a pop up page that will display the details. Straightforward.

    However my client would like to be able to have a previous / next link displayed beneath the details so that the visitor can also nove 'backwards' and 'forwards' through the items without going back to the main list.

    For this it seems I would need some code that knows what 'item' is being displayed and be able to call up a link to the 'previous' and 'next' items. The table does contain a 'sortorder' field in which the client enters a number to specify the position of each item in the list. This would seem a natural contender but currently this can be any number they like.

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    All your news items should be given an item ID, then you just need to query your database to find the next ID up and down from the current position.

    Code:
     
    For the next item
    SELECT item_ID 
    FROM table 
    WHERE item_ID > '$currentitemid' 
    ORDER item_ID ASC 
    LIMIT 1;
     
     
    For the previous
    SELECT item_ID 
    FROM table 
    WHERE item_ID < '$currentitemid' 
    ORDER item_ID DESC 
    LIMIT 1;
    Should get you most of the way there
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks

    thank you Mandes

    Your solution was right on the money! all done.


Bookmarks

Posting Permissions

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