SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Saving the MySQL query

    Hello,
    This may be a question for the PHP area, but I am not really sure.

    You see, what I want to do is this:
    • Once the user preforms a search, they click on an item
    • After they click on that item, they can click "next item" without going back to the initial search result page.
    Can anyone point me in the right direction for this one?

  2. #2
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that's just pagination really and is PHP related.

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Isn't pagination when you return results and you have the results cut into multiple pages:
    Prev 1, 2, 3, 4, 5 Next

    What I want to do is to have Prev and Next not on the search results page, but on the item which is displayed. How do you tell MySQL (or PHP) which items would be next in the previous result page?

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your items are indexed with ids such as 1,2,3,4,5 then you just write the current item id - 1 for previous item id and current item id + 1 for next item id. This would be the easiest way in my opinion. Just simple math.
    Kayzio - We don't hesitate, we accelerate.

  5. #5
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It's the same as pagination with 1 item per page. You just keep reissuing the same query while incrementing the values in the LIMIT clause by 1.

  6. #6
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kayzio,
    The search page will likely output a search with results that do not increment so neatly. A search page my return results: 1, 5, 9, 22

    Dan, I think I know what you're saying. When I click on the item, I will have to pass the whole search query again to that page as well. Correct?

  7. #7
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yes, you'll need to keep track of enough information to execute the same query each time the back/next link is clicked. You'll probably be passing whatever search parameters the user entered. The links will contain the same parameters but a different page number (although you might not call it that); back one less than current, and next one more than current.

  8. #8
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The light bulb just turned on. Thanks for your help!


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
  •