chrissparkle
Programmer
I have a table of members which has 5 tinyint fields labelled Love, Friendship, Marriage, Casual, Anything (these are options that the member might be looking for). A member can select one or all of them (if it's selected it's 1, if not it's 0).
I'm doing my search proc at the moment and am giving the user the option tick which of the 5 they would like to search on - they can tick any number of them.
How do I do this in the SQL query though? I thought it would simple until I actually came to write it and realised it wasn't so simple.
What I think I need to do is just search on what the user has wanted to search for. So if a user wants to search on Love and Friendship I think my SQL should look something like this:
That's easy enough, but I don't know how to exclude what is not being searched on because I'm passing in all 5 variables into my proc, and they'll each either be 1 or 0 depending on if they've been ticked.
So I guess my question is how can I include only what I want to search on, and exclude those fields from the WHERE clause that are 0?
I'm doing my search proc at the moment and am giving the user the option tick which of the 5 they would like to search on - they can tick any number of them.
How do I do this in the SQL query though? I thought it would simple until I actually came to write it and realised it wasn't so simple.
What I think I need to do is just search on what the user has wanted to search for. So if a user wants to search on Love and Friendship I think my SQL should look something like this:
Code:
SELECT * From Members
Where (Love = 1 OR Friendship = 1)
That's easy enough, but I don't know how to exclude what is not being searched on because I'm passing in all 5 variables into my proc, and they'll each either be 1 or 0 depending on if they've been ticked.
So I guess my question is how can I include only what I want to search on, and exclude those fields from the WHERE clause that are 0?