SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2003
    Location
    sydney, Australia
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Keeping search results, user has 'sort by' option

    Would anyone have an idea how to keep a search result so that user will be able to sort these results based on variuos options?

    I was thinking that one way to do this is to pass the MySQL query as a hidden field in an html form with sort by options.

    eg. In a search result page, there will be a form with a drop down list of 'sort by' options: dates, name, price, etc. When it is submitted, 2 things will be passed: the previously mysql query containing all filters submitted, and the new sort-by field. The next page will simply add a string of 'ORDER BY something' to the previously posted MySQL query. and eventually queries the database, and shows the results.

    However with this method, everytime user wants to re-sort the search results, new mysql query needs to be created.

    I don't think it is a very efficient technique, especially if the search results are large.

    In Kevin Yank's article "Object Oriented PHP: Paging Result Sets", I believe the same issue is of concerned. Everytime a page is chosen (from the navigation), a new MySQL query will be created.

    I'm sure there's someone that knows a more efficient way in doing this. Maybe we can session_register the search results? but with this session_register, how would know when we should session_unregister it? or another way i thought is just to serialize the search results, and put it as hidden field in sort-by form.

    Could any gurus please share it with us?

  2. #2
    SitePoint Addict
    Join Date
    Dec 2002
    Location
    Gent, Belgium, Europe, World, Univers
    Posts
    397
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have no idea how to do it without querying the database each time ...

    What I do know is, you can's put the query into your form. It's ok to have the sort options in the form and all, but not the entire query.

    A form doesn't stop a user to submit any info to the server he wants, that way he can submit DROP, DELETE and many more queries and your PHP code would execute him ... Which isn't good ofcourse ...

  3. #3
    SitePoint Member
    Join Date
    Sep 2003
    Location
    sydney, Australia
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    kajakske: I know that we can pass any kinds of variables through session_register($var), including objects. Or serialize the variable first, in this case is the query string, and pass it as hidden field.

    But with session_register, we won't know when to session_unregister the search results... and also if the search results is big, it is not practical to serialize/ session_register this object.

    So... can anyone help here? I'm sure it's a simple thing, it's just I can't find it anywhere...

    Any help will be appreciated.
    Thanks.


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
  •