Page 1 of 1

Help - Database results from selections

Posted: Thu Nov 24, 2005 2:52 pm
by mhouldridge
Hi,

I am working on a search page which has the following selection boxes;

Location
Property type
Number of bedrooms
Price

I have never done a search query using multiple selection boxes.

Please help!

Posted: Thu Nov 24, 2005 3:51 pm
by neophyte
For each drop down determine if the pulldown not empty. If it isn't empty make a where statement out of the data.

Code: Select all

if (!empty($_POST['location')){
    $location = "location = ".$_POST['location']; //make sure you sanitize the data first 
} else {
    $location = ""; //It's empty no qualifier.
}
Do something similar for each pull down. Then make the query.

Code: Select all

$sql = "SELECT * FROM sometable WHERE ".$location." ".$someother;
Execute it and your done.

Hope that helps.

If you have multiple tables you'll have to calculate first if joins are necessary and so forth.