Help - Database results from selections

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Help - Database results from selections

Post 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!
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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.
Post Reply