doulie0178 2012-07-10 08:15
浏览 65
已采纳

FIND_IN_SET出错

i am getting result in phpadmin for this query but getting error in 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

Where LP.luxury_property_feature_id is comma separated value

What is the issue in this query?

Updated:

I am executing like this

$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";

Where $luxPropFeatures is checkbox selected array

  • 写回答

1条回答 默认 最新

  • duanlang1196 2012-07-10 09:41
    关注

    Finally i fixed the issue,

    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) ";
        }
    
    }
    

    Previously i tried to escape the OR [OR FIND_IN_SET('2',LP.luxury_property_feature_id) OR FIND_IN_SET('7',LP.luxury_property_feature_id)]character for the first time like $str[0]='';$str[2]='';

    Instead of set null, i trimmed the first two char using ltrim [$trimmed = ltrim($str, "OR"); ]

    Now its working fine, thanks for the support.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!