1

我正在尝试搜索我正在为朋友开发的房地产网站。在数据库中,属性类型由 id 编号命名,即:house = 30、flat = 8、t Terrad = 1,依此类推。

当一些是价值为 2 且房屋价值为 30 等的独立式住宅时,我如何从数据库中检索所有属性 :) 它让我陷入困境..lol 这是我到目前为止所拥有的,但它不起作用......

$bedrooms = $_GET['bedrooms'];
$pricefrom = $_GET['pricefrom'];
$priceto = $_GET['priceto'];
$proptype = $_GET['proptype'];

if($proptype == 'house'){
$search_propsubid = array('1,2,3,4,5,6,21,22,23,24,26,27,30');
}elseif($proptype == 'flat'){
$search_propsubid = array('7,8,9,10,11,28,29,44');
}elseif($proptype == 'bungalow'){
$search_propsubid = array('');
}


$sql = mysql_query("SELECT * FROM `properties` WHERE `PROP_SUB_ID`='$search_propsubid' AND `BEDROOMS`='$bedrooms' AND `TRANS_TYPE_ID`='1' HAVING `PRICE` BETWEEN '$pricefrom' AND '$priceto' ORDER BY `UPDATE_DATE` DESC");

谢谢你的时间,我希望有人能指出我正确的方向.. 问候史蒂夫

4

2 回答 2

1

您可以尝试内数组:

$search_propsubid = array('1,2,3,4,5,6,21,22,23,24,26,27,30');
$comma_separated = implode(",", $search_propsubid);
$sql = mysql_query("SELECT * FROM `properties` WHERE `PROP_SUB_ID` in ($comma_separated) ...

如果这对您不起作用,请返回新闻。

于 2012-05-27T01:31:17.137 回答
1

您可以使用MySql IN()比较运算符来选择与值列表匹配的所有值:

$sql = mysql_query("
  SELECT * 
  FROM `properties` 
  WHERE `PROP_SUB_ID` IN (" .implode(",", $search_propsubid). ")
  AND `BEDROOMS`='$bedrooms' 
  AND `TRANS_TYPE_ID`='1' 
  HAVING `PRICE` BETWEEN '$pricefrom' AND '$priceto' 
  ORDER BY `UPDATE_DATE` DESC
");

假设$proptype == 'flat',输出将是:

SELECT *
FROM `properties` 
WHERE `PROP_SUB_ID` IN (7,8,9,10,11,28,29,44) 
...
于 2012-05-27T01:33:55.823 回答