Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding to a search

Status
Not open for further replies.

peasepud

Programmer
Jul 20, 2007
35
0
0
Hi,

Im developing a site which allows the user to search on a dozen different criteria each time narrowing down and displaying the results.

I currently have it working by merely adding the AND newsearchcriteria on the end of the last search so you get

SELECT * FROM table where person = female

returning 100 results so user clicks "taller than 1 metre"

to give

SELECT * FROM table where person = female and height > 12 (Im storing the likes of height in a dropdown)

to give 30 results then "age below 50"

to add "AND age < 50" to the query etc etc etc

the 'problem' I have (and its merely performance and tidyness) is that a user could also then click "taller than 1.5 metres" which would still give the same correct recordset back but would make the query...

SELECT * FROM table where person = female and height > 12 AND age < 50 AND height > 15

thereby giving an unneeded height, at the same time I need to allow the facility for two heights to be present to allow users to say > 1 metre and < 1.5 metres for instance.

The idea I have in my head (which is almost always wrong) is to have an array containing the start of each criteria as its added so the array in the case above (before the 2nd height) would be:

field value
"height >" 12
"age <" 50

and each time a new search is carried out it would check if the field existed, if so amend the value and if not add it as a new entry.


So (after 3 pages of waffle) does this make sense to do it this way or am I missing a simpler more sensible option?
 
i would not worry too much about duplicating where clauses. unless you're talking about 100s of millions of records, i doubt whether it will have an effect. you will get greater performance gains from making sure your indexes are well designed.

that said, your idea of storing the query parameters in an associative array sounds good.
 
I think this really does not matter as the query optimizer is smart enough to take care of it for you. Not worth your effort :)

- Shelon Padmore
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top