Welcome Guest, Not a member yet? Register   Sign In
What is best way to handle complex search?


I am currently using get method to retrieve parameters and query database.
The problem I am having is I need to preserve the current query parameters and allow user to narrow search.

Example url

Now the user can click on a image of products and I want to narrow the search while still using the original parameters.

New url show pick_brand filter

Is this the best method to search, url looks ugly.
Or should I use post and store in session variable?

How would you do it?


I think it really depends on whether you need the search to be bookmarkable or shared. If you want it to be shareable then you'll have to use $_GET vars. To clean it up, though, you might consider some form of tokenization, either by creating a unique token and storing the params in the database for 30 days, or something, or maybe by serializing and base64 encoding the array? That might not give you exactly what you are looking for, but something like that should be able to work.

If not, then I would keep it clean and go with POST, but I wouldn't store it in the session. If it was their cart then I'd definitely consider the solution, but for a search it doesn't need to last so no sense taking up precious session space. Instead, I'd maintain the values throughout the search request. Then I'd put it in hidden form inputs one the page so it's available on every search.

Thanks, I like the POST solution, but after they post the search, the remainder options use anchor to pass the id.
How can I keep the post data with the anchor data throughout the search?

For my experience, using $_GET is more appropriate for perform searching and filtering as well as shareable ( as kilishan said ). if you're using $_POST the page will popup resubmit form alert every single time when the page is refresh.

For other case, they also use session for keep user's search text and filtering preferences. disadvantages of this user cant do multiple tab with different search and filter.

Thanks, I will keep it using the GET logic.

Theme © iAndrew 2016 - Forum software by © MyBB