2016-10-13 10 views
1

このエラーが発生しました。何がうまくいかないかを判断できませんでした。SQL構文のエラー

は、データベースエラーが発生しました

エラー番号:1064

あなたのSQL構文でエラーが発生しています。ライン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() 

に ')' は 近くを使用する権利構文についてはMySQLサーバのバージョンに対応していること取扱説明書を確認してくださいMy機能は次のようになります。

\t function get_nomination_emailids($functions, $levels, $roles, $locations, $emails) 
 
\t \t { 
 
\t \t \t 
 
\t \t \t $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' "; 
 
\t \t \t if(count($functions)>0) 
 
\t \t \t { 
 
\t \t \t \t $d = implode(",",$functions); 
 
\t \t \t \t $whereand[] = " u.departmentid IN (".$d.") "; 
 
\t \t \t } 
 
\t \t \t if(count($levels)>0) 
 
\t \t \t { 
 
\t \t \t \t $d1 = implode(",",$levels); 
 
\t \t \t \t $whereand[] = " ud.designation_id IN (".$d1.") "; 
 
\t \t \t } 
 
\t \t \t if(count($roles)>0) 
 
\t \t \t { 
 
\t \t \t \t $d2 = implode(",",$roles); 
 
\t \t \t \t $whereand[] = " u.userroleid IN (".$d2.") "; 
 
\t \t \t } 
 
\t \t \t if(count($locations)>0) 
 
\t \t \t { 
 
\t \t \t \t $d3 = implode(",",$locations); 
 
\t \t \t \t $whereand[] = " u.branchid IN (".$d3.") "; 
 
\t \t \t } 
 
\t \t 
 
\t \t \t if(count($emails)>0) 
 
\t \t \t { 
 
\t \t \t \t $d4 = implode(",",$emails); 
 
\t \t \t \t $whereor[] = " ud.userid IN (".$d4.") "; 
 
\t \t \t } 
 
\t \t \t $whr = array(); 
 
\t \t \t 
 
\t \t \t if(isset($whereand)) 
 
\t \t \t $whr[] = " (".implode(" AND ",$whereand).") "; 
 
\t \t 
 
\t \t \t if(isset($whereor)) 
 
\t \t \t $whr[] = " (".implode(" OR ",$whereor).") "; 
 
\t \t \t 
 
\t \t \t 
 
\t \t \t if(count($whr > 0)) 
 
\t \t \t { 
 
\t \t \t \t 
 
\t \t \t \t $SQL .= " AND (".implode(" OR ",$whr).") "; 
 
\t \t \t } 
 
\t \t \t 
 
\t \t \t $query = $this->db->query($SQL); 
 
\t \t 
 
\t \t \t $return \t = \t $query->result_array(); 
 
\t \t \t 
 
\t \t \t return $return[0]['id']; 
 
\t \t \t //print_r($return);die; 
 
\t \t \t 
 
\t \t }

+5

AND()には何かが含まれている必要があります。 –

+0

Btw 'count()'は、配列またはNULLでないすべての項目に対して '1'を返します。したがって、 '$ emails'または' $ locations'が__FALSE__ならば、countは1です。 –

答えて

-1

クエリでAND()を削除してください。

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'