duanfei1975 2016-10-13 10:09
浏览 17

too long

I am getting this error , Not able to make out what is going wrong , please help.

A Database Error Occurred

Error Number: 1064

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 GROUP_CONCAT(DISTINCT ud.userid) as id from pr_users_details ud INNER JOIN pr_users u ON ud.userid = u.id WHERE ud.status = '1' AND ()

My function looks like this:

    function get_nomination_emailids($functions, $levels, $roles, $locations, $emails)
        {
            
            $SQL.="SELECT GROUP_CONCAT(DISTINCT ud.userid) as id from pr_users_details ud INNER JOIN pr_users u ON ud.userid = u.id  WHERE ud.status = '1' ";
            if(count($functions)>0)
            {
                $d = implode(",",$functions);
                $whereand[] = " u.departmentid IN (".$d.") ";
            }
            if(count($levels)>0)
            {
                $d1 = implode(",",$levels);
                $whereand[] = " ud.designation_id IN (".$d1.") ";
            }
            if(count($roles)>0)
            {
                $d2 = implode(",",$roles);
                $whereand[] = " u.userroleid IN (".$d2.") ";
            }
            if(count($locations)>0)
            {
                $d3 = implode(",",$locations);
                $whereand[] = " u.branchid IN (".$d3.") ";
            }
        
            if(count($emails)>0)
            {
                $d4 = implode(",",$emails);
                $whereor[] = " ud.userid IN (".$d4.") ";
            }
            $whr = array();
            
            if(isset($whereand))
            $whr[] = " (".implode(" AND ",$whereand).")  ";
        
            if(isset($whereor))
            $whr[] = " (".implode(" OR ",$whereor).")  ";
            
            
            if(count($whr > 0))
            {
                
                $SQL .= " AND (".implode(" OR ",$whr).") ";
            }
            
            $query = $this->db->query($SQL);
        
            $return =   $query->result_array();
            
            return $return[0]['id'];
            //print_r($return);die;
            
        }

</div>
  • 写回答

1条回答 默认 最新

  • dongliao9018 2016-10-13 11:00
    关注

    AND() remove in your query try this.

    SELECT GROUP_CONCAT(DISTINCT ud.userid) as id from pr_users_details ud INNER JOIN pr_users u ON ud.userid = u.id WHERE ud.status = '1'
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭