1
我得到这个错误,无法弄清楚怎么回事,请帮忙。SQL语法错误
数据库出错
错误编号:1064
您的SQL语法错误;检查 对应于你的MySQL服务器版本正确的语法使用 附近 ')' 在行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()
我的功能看起来像这样的手册:
\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 }
'AND()'需要包含或删除它们。 –
Btw'count()'返回每个不是数组或NULL的项的'1'。所以如果'$ emails'或'$ locations'是__FALSE__ count是1。 –