我有大量数据(房屋清单)需要能够被用户过滤。最小/最大卧室数量、最小/最大价格范围、郊区、房产类型。
我创建了一个带有过滤选项的数组,但是只有在选择了所有选项时查询才有效。我需要有能力让它工作它只选择一个选项。
关于我应该如何解决这个问题的任何想法?
$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());
}