I am working on a real estate project and am working on a form that allows the user to select a borough and/or a listing type. The problem is that I am not sure how to work the "or" part of the query if the user only selects one filter from the form (my current query only works if both filters are selected). I know that you probably have to use a "Case" clause but I am not sure how to use it. My code that handles the form variables and inserts them into a query on the PHP page is below: (lines 7 and 8 contain the form variables)
Code: Select all
//Declare variables being passed into this page
$QueryType = $_GET['Type'];
$QueryBorough = $_GET['Borough'];Code: Select all
$ListingsQuery = "select l.ListingID as ListID, l.Image, l.tbType_TypeID, t.TypeName, b.Borough, l.City, l.Price, l.Rooms, l.OpenHouse
from tbListing l
join tbBorough b on b.BoroughID = l.tbBorough_BoroughID
join tbType t on t.TypeID = l.tbType_TypeID
where l.Void = '0'
and l.Sold = '0'
and l.tbType_TypeID = '$QueryType'
and l.tbBorough_BoroughID = '$QueryBorough'";
$FindListings = mysql_query($ListingsQuery);