Not sure if this is the most efficient way, but instead of setting up
the IF statement to pick between two different queries, use it to build
the query.
Sort of like:
$sql = "select * from table1 where [all your 'standard items' here]";
If(!empty($stories)) {
$sql .= "and where stories='$stories'";
}
Switch($waterfront) {
Case "yes" :
$sql .= "and where waterfront='yes'";
Break;
Case "no" :
$sql .="and where waterfront='no'";
Break;
}
... and so on for any other items.
Then finish off the statement:
$sql .= "order by whatever limit, 0,10;";
Hope this is what you where looking for. I'm sure some of the gurus can
chime in here and give a more efficient/elegant answer.
Conor
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of fredbird67
Sent: Wednesday, March 08, 2006 10:10 AM
To: [email protected]
Subject: [php-list] How to deal with "no-preference" selections?
I'm working on a searchable database of properties for a realtor who's
invested in some properties down in Florida. While I've got things
working with most of the search parameters (price, square footage,
number of bedrooms and bathrooms, and number of cars the garage will
hold), I'm kinda stumped on something here:
I'm also including a search parameter for number of stories, with the
selection possibilities being no preference, one story, one and a half
stories, two stories, and split-level. The question is, how am I
supposed to make the database select from all "stories"
classifications when a user selects "no preference"?
True, I could set up an IF statement that would choose between two
SELECT queries, one of which would and the other of which would not
filter the number of stories, but there's also a field for whether or
not one wants a waterfront property, and if I get another such field
in there like that where one can select from stuff like that that's
not all that easy to do with numbers, unlike the price, square
footage, etc., then things will get messy, and I'd like to avoid that
if at all possible.
Any ideas? I just know that this is possible to do, because I'm sure
I've seen something like this done on other websites, but just how is
beyond me at the moment. I've used PHP on a few sites before (mostly
include statements), but this is the first time I've ever created a
site that searches a database.
Community email addresses:
Post message: [email protected]
Subscribe: [EMAIL PROTECTED]
Unsubscribe: [EMAIL PROTECTED]
List owner: [EMAIL PROTECTED]
Shortcut URL to this page:
http://groups.yahoo.com/group/php-list
Yahoo! Groups Links
Community email addresses:
Post message: [email protected]
Subscribe: [EMAIL PROTECTED]
Unsubscribe: [EMAIL PROTECTED]
List owner: [EMAIL PROTECTED]
Shortcut URL to this page:
http://groups.yahoo.com/group/php-list
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php-list/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/