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>

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'