I have a problem I'd like to run past some of the more database savvy people around here. I have a search form with various fields like username, phone no, etc.
Users may fill in the form and what I want is a query that will be constructed depending on the fields they fill in. For example, say they fill in the username and the phone number fields. I want to 'select * from contacts where username=$blah1 AND phone_no=$blah2'. Then if someone else fills in just the username it has to build 'select * from contacts where username=$blah1'.
Basically I'm trying to find and easy way to firstly check which variables are not empty strings, and construct a query consisting of a base 'select * from contacts' and then joining in the rest, firstly using a 'where' and from then on 'AND'.
If you have any idea what I'm talking about please let me know what you think.
TIA
Matt
Users may fill in the form and what I want is a query that will be constructed depending on the fields they fill in. For example, say they fill in the username and the phone number fields. I want to 'select * from contacts where username=$blah1 AND phone_no=$blah2'. Then if someone else fills in just the username it has to build 'select * from contacts where username=$blah1'.
Basically I'm trying to find and easy way to firstly check which variables are not empty strings, and construct a query consisting of a base 'select * from contacts' and then joining in the rest, firstly using a 'where' and from then on 'AND'.
If you have any idea what I'm talking about please let me know what you think.
TIA
Matt