Selecting a LARGE list (with filters) and PDO

Swobredxejepd

New Member
I have a large list of data (house listings) that needs to have the ability to be filtered by the user. min/max amount of bedrooms, min/max price range, suburbs, types of properties.I have created an array with the filtering options however the query only works if ALL the options are selected. I need to have the ability for it to work it only one option is selected. Any ideas on how I should go about this? \[code\]$query = $db->prepare("SELECT *, (SELECT MIN(FileName) as FileName FROM `images` WHERE `images`.`PropertyID` = `property`.`PropertyID` order by `images`.`id` asc) as FileName FROM `property` INNER JOIN `features` ON `property`.`PropertyID` = `features`.`PropertyID` WHERE `property`.`Active` = '1' AND `property`.`homelink` = '0' AND `property`.`Suburb` = :suburb AND `features`.`Bedrooms` >= :bedroom_min AND `features`.`Bedrooms` <= :bedroom_max AND `property`.`Rent` >= :price_min AND `property`.`Rent` <= :price_max AND `property`.`PropertyType` = :property_type GROUP BY `property`.`propertyid` ORDER BY `property`.`AdvHeading` = 'LEASED!' ASC, `property`.`rent` DESC");$vars = array(suburb,bedroom_min,bedroom_max,price_min,price_max,property_type);foreach($vars as $key) { ${$key} = (isset($_GET[$key]) === true) ? $_GET[$key] : ''; $query->bindValue(':'.$key.'', ${$key}, PDO::PARAM_STR); }try { $query->execute(); $rows = $query->fetchAll(PDO::FETCH_ASSOC); echo '<pre>', print_r($rows, true), '</pre>';} catch(PDOException $e){ die($e->getMessage()); }\[/code\]
 
Back
Top