SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Next Previous

  1. #1
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Next Previous

    Hi There,

    I trying to do a next/previous links.

    The current page has a querystring("ID) example ID=15.

    What I need to do is retive the previous entry ID this could be 14 or 7 or 2.
    I am also trying to do this the next up ID so it could be 16 or 58 or 56989.

    example code if the querystring is 15

    Code:
    <a href="?section=main&id=7><< Previous</a>
    <a href="?section=main&id=45>Next >></a>
    The ID number will change depending on the next or previous record ID.

    Any thoughts

    Thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2010
    Location
    Dana Point, CA
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The best option I can come up with would be two separate queries.

    SELECT TOP 1 ID FROM [tblName] WHERE ID < 15 ORDER BY ID DESC;

    SELECT TOP 1 ID FROM [tblName] WHERE ID > 15 ORDER BY ID;

  3. #3
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    How do you know the next or previous ID number is not +1 or -1 from the current ID?

    Remember that in a database all the records are effectively unsorted - like a bucket full of golf balls with numbers on them. They only become sorted in some way when you take them out (i.e. create a recordset) - and it is the act of taking them out that defines the sort method and order.

    Perhaps if you describe your database table, give some example data, and explain what you're trying to achieve (i.e. how you know which record is going to be the next or previous one) then we might be able to help.
    Ian Anderson
    www.siteguru.co.uk

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    add next and previous values in global variable. and just call this variable
    AI Logica eCommerce + CMS Website from 300 - Limited Time Offer
    HaqTech Electronics UK
    SEO Webmaster Forums

  5. #5
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    359
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Remember that in a database all the records are effectively unsorted - like a bucket full of golf balls with numbers on them. They only become sorted in some way when you take them out (i.e. create a recordset) - and it is the act of taking them out that defines the sort method and order.
    That's a very nice description!
    Doug G
    =====
    "If you ain't the lead dog, the view is always the same - Anon

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I was going to say Bingo balls, but that might not have translated so well.
    Ian Anderson
    www.siteguru.co.uk


Tags for this Thread

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
  •