Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts

    next rec, previous rec

    Is there a way to create "next" and "previous" buttons on an item page?
    It seems to be a hard work to let the server load all the records and then finding the next or the previous.
    Is there a 'cheaper' way?

    Thanks.

  • #2
    Registered User
    Join Date
    Jan 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well...when loading the page you're selecting the information for that Item and I would assume that the item has an itemkey in the table.

    So couldn't you just select the itemkey + 1 and itemkey - 1.

    Of course...assuming you want to cycle straight down the db.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    it has an item key.
    but it's not subsequent

    it was very easy to program if it was

  • #4
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    The best way to do this is like the below. You just query for the one record so you don't have to worry about retrieving all records. The query string is then used to pick which record. This also allows people to bookmark an item, which is really recommended.

    Example URL: http://site.com/itemdisplay.asp?item=1
    Code:
    item_num = Request.QueryString("item") - 1
    query = "SELECT * FROM table LIMIT " & item_num & ", 1"
    ' Run query
    ' Query will pick whatever record is chosen in the query string
    The previous button (display if item_num is greater than 0):
    Code:
    Response.Write "<a href=""itemdisplay.asp?item=" & item_num-1 & """>Next</a>"
    The next button (display if item_num is less than the record count):
    Code:
    Response.Write "<a href=""itemdisplay.asp?item=" & item_num+1 & """>Next</a>"
    -Shane

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Is the limit clause works with Access?
    Where can I read about it (I googled it and didn't find something useful).

  • #6
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    Sorry, didn't realize you were using Access. Should of figured since this is ASP. Access is a bit weird in this area (along with MS SQL Server). My previous solution is with most other databases like MySQL and PostGreSQL.

    You can do something like:
    Code:
    item_num = Request.QueryString("item")
    If (item_num > 1) Then
      query = "SELECT TOP " & item_num & " * FROM table WHERE itemkey NOT IN (SELECT TOP " & item_num - 1 & " * FROM table)"
    Else
      query = "SELECT TOP " & item_num & " * FROM table"
    End If
    Or:

    You can just query the entire recordset and you can use the Move command on the recordset and specify the record number from the query string.

    -Shane


  •  

    Posting Permissions

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