Searching MySQL

admin

Administrator
Staff member
Hi,

I'm trying to make a simple search page to search a MySQL database. Instead of the usual text box, I have generated a form that is made up 5 pull-down menus that corresponds to 5 fields on my data table. The searcher can then pick which values in those fields to look for and I run a query like:

select * from table_name where field_1 = 'value_1' and field_2 = 'value_2' ... and so forth and so on until field_5.

My problem is this: for the search to be flexible I would like the user to be able to set any of the pull-downs to "any" and thus run a more non-specific search wherein one or more of the conditions are "disabled", so to speak. Is there any value I can assign to 'any' such that I can still use the query above. or how should I do this?

Defining different queries using 'if' statements seems too impractical a solution since with 5 pull-downs I'd have to consider a headsplitting number (120?) number of permutations (i.e. if user picked 'any' on the first pulldown and something specific on each of the other 4, 'any' on the first 2 and something specific on the other 3, etc, etc...).

This is probably pretty simple, sorry, but am a novice.

Thanks,
Solomon
 
Back
Top