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.

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

报告相同问题?

悬赏问题

  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决