View Full Version : remembering a user search query.

11-20-2012, 01:42 PM

I have a listings website where users can search with various criteria, such as below;

area: 'London'
date: '2nd November'
price: 'less than 5'

this is then put into the URL query string... mywebsite.com/search.php?area=london&date=02112012 etc...

I want the users to be able to save their search for future use, accessable from a hyperlink in their home area.

I see two solutions...

1. creating a table in my database with the rows, 'memberid', 'area' , 'date', 'price' and store them this way. With any search fields being left blank inserting a NULL value. I would then build the URL with php echo's from the database like mywebsite.com/search.php?area=<?php echo $row['area']?> etc...

2. Saving the entire URL into the database with use of $_SERVER features, linked to the members ID.

I'm pretty sure the 1st option is the way to go, but is there any other method that would be better for this before I begin working on it?

Any advice would be appreciated.


11-20-2012, 02:44 PM
I would go with Option number 2 personally...it involves less work during storage and retrieval and therefore faster though it's a negligible increase in speed. You only have to fetch one row per search unlike Option 1. Unless of course you have database space in Kilobytes and you want to save as much space as possible because saving all search queries in a Listings website could escalate quickly :)

11-20-2012, 04:44 PM
Thanks for you help. I've had more of a think about it and the features i can offered the user, and realised the first option would actually provide me with a handy tool for showing 'suggested searches'. I could find the fields the user commonly has saved, such as 'price: under 5', and 'London', and suggest them events based on their previous searches... would be quite handy. I don't think that's as easy with the second option.

cheers though, much appreciated.

btw, i checked out the link on your signature and i'm not sure if you're aware but theirs a conflict in the amount of pages you offer for pacakges in the footer of your site compared to the actually 'web design' page. (just a heads up :))

11-20-2012, 05:14 PM
The suggested searches would definitely not be possible with Option 2. Not impossible but not very possible hehe.

Thanks for the heads-up about the signature. I will change it when I get back home Appreciated. :)