SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2001
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    formatting lengthy search results over multiple pages

    I'm building a search function into a site of mine, and I want to display only a reasonable subset of the search results on any given results page. So, if the user does a search that returns 80 records, I want to show the first twenty records and then provide links at the bottom of the page to allow the user to see the rest of the results. (Think Google.)

    My problem is that I'm not sure how best to keep the query results persistent as the user jumps from page to page. I don't want to run the query again each time the user asks for the next twenty results, on the off chance that the data in the database has been updated by another user in the meantime.

    The only strategy I can think of is to store the entire result set as a session variable. Assuming this would work (I haven't tried coding it yet), it doesn't seem like a very elegant solution.

    I guess another approach might be to make each search results page an actual form, and pass the query results around from page to page as a hidden input type.

    I suppose a third approach is to try to save the query results in the database itself, and retrieve them as the user passes from page to page. Again, pretty complicated.

    Do any of these suggestions sound promising? Can anybody think of a simpler way to handle the problem?

    Kevin McCulloch
    San Francisco, CA

  2. #2
    SitePoint Guru Majglow's Avatar
    Join Date
    Aug 1999
    Location
    B-Town
    Posts
    645
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    What I would do is redo a query each time, but I would make mySQL limit the results using "LIMIT x, y" in the query and using a "SELECT count(*)" whent the search is initially made to find out how many records there are in all that match the search.

    Carl
    Ohai!

  3. #3
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used to do that myself, but that means you would either have to A) run another query to get the total number of records every single time the page is loaded, or B) pass the total number of results in the querystring...neither of which is all that great, IMO.

    Personally, what I do is select one more record than I intend to display on that page. If the number of results reaches that number, I know that I need to create a "next" link. Fairly simple in that respect...I was quite pleased with myself when I did eventually think of it.


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
  •