0

我在 phpadmin 中得到这个查询的结果,但在 php( You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1)中得到错误

select * from luxury_properties LP,property_type PT,cities C 
where (FIND_IN_SET('2',LP.luxury_property_feature_id) OR 
       FIND_IN_SET('7',LP.luxury_property_feature_id) ) 
AND LP.property_type_id = PT.property_type_id 
AND LP.city=C.city_id 
AND LP.status=1 
order by LP.property_price DESC

LP.luxury_property_feature_id逗号分隔值在哪里

这个查询有什么问题?

更新:

我正在这样执行

$str='';
if(is_array($luxPropFeatures) && $luxPropFeatures != 0)
{
    $selCount = count($luxPropFeatures);
    if($selCount >1){
        foreach($luxPropFeatures as $val){
            $str .= " OR FIND_IN_SET('".$val."',LP.luxury_property_feature_id) ";
            $str[0]='';$str[1]='';
        }
    }else{
        foreach($luxPropFeatures as $val) {
            $str = " FIND_IN_SET('".$val."',LP.luxury_property_feature_id) ";
        }
    }
}


$sql = "select * from luxury_properties LP,property_type PT,cities C 
        WHERE (".$str.") 
        AND LP.property_type_id = PT.property_type_id 
        AND LP.city=C.city_id 
        AND LP.status=1 
        order by LP.property_price DESC";

$luxPropFeatures复选框选择的数组在哪里

4

1 回答 1

2

最后我解决了这个问题,

if($selCount >1){
    foreach($luxPropFeatures as $val) {
    $str .="OR FIND_IN_SET('".$val."',LP.luxury_property_feature_id) ";
    $trimmed = ltrim($str, "OR"); 
     //$str[0]='';$str[2]='';
     }
}else{

    foreach($luxPropFeatures as $val) {
        $trimmed = "FIND_IN_SET('".$val."',LP.luxury_property_feature_id) ";
    }

}

以前我第一次尝试转义OR[ OR FIND_IN_SET('2',LP.luxury_property_feature_id) OR FIND_IN_SET('7',LP.luxury_property_feature_id)] 字符$str[0]='';$str[2]='';

我没有设置 null,而是使用 ltrim [ $trimmed = ltrim($str, "OR");]修剪了前两个字符

现在可以正常使用了,感谢支持。

于 2012-07-10T09:41:04.200 回答