Forum Moderators: coopster
I have a form with multiple choices to choose from to find an apartment from our database. When they choose what ever they want on the form it does a GET to my listings search page.
So for each individual field i have for instance
$price = $_GET['price'];
$hood = $_GET['hood'];
$doorman = $_GET['doorman'];
Now i have two table where this info needs to be pulled from an apartments table and a buildings table. So all along i have bee using this query
$query = "SELECT * FROM apts INNER JOIN buildings ON apts.buildid = buildings.buildid AND frontend = 'TRUE'"
to get the two joined together. BUT what im finding is i can't do OR statments with this query I can really only do AND statements. Then im relizing i may have to do 720 different if statements there is no way.
Regardless heres how it looks in the address bar when it does its GET to the listings search page:
/listingsearch2.php?hood=Upper+East+Side&pricelow=1000&pricehigh=3000&doorman=Yes
&elevator=Yes&pets=Yes&outdoor=Yes&beds=1&baths=1&Submit=Search+For+Your+Next+Apartment
So my questions is whats the best way to search two tables for these results in any way the user decides they want to search from the form (i.e Hood & Beds or Hood and Price, or Hood, Price, Bed and Doorman)
THANK YOU AHEAD OF TIME!
[edited by: coopster at 10:22 pm (utc) on May 11, 2006]
[edit reason] broke query string to fix sidescroll [/edit]
I would initialize a WHERE clause and append to it.
$hood = (isset($_GET['hood']))? trim($_GET['hood']) : '';
$whereClause = 'WHERE 1=1';
if ($hood) {
$whereClause .= " AND hood = '" . mysql_real_escape_string($hood) . "'";
}