2016-09-18 3 views
0

CodeIgniter 쿼리 빌더를 사용하고 있습니다. 거기에 having 절을 추가하고 싶습니다. 이 (내가 쿼리의 다른 부분 생략) : 다음과 같이 내 코드 보인다Codeigniter IN 문을 가진 쿼리 빌더 having 절

$this->db->having($filterarray); 

을 그리고 난 다음과 같이 미리 filterarray를 구축 :

$filterarray = array(); 
     if (!empty($filters['interests'])) { 
      $interestids = $this->interests_model->getAllIdsByDescription($filters['interests']); 
      $filterarray['interests IN'] = $interestids; 
     } 

내 기능 getAllIdsByDescription은 다음과 같습니다

function getAllIdsByDescription($names){ 
    $res = "("; 

    $query = $this->db->where_in('description', $names) 
     ->select('interest_id') 
     ->get($this->tableName); 
    foreach ($query->result() as $interestid) { 
     $res .= $interestid->interest_id; 
     $res .= ", "; 
    } 
    $res = substr($res, 0, -2); 
    $res .= ")"; 
    return $res; 
} 

은 내가 오류를 따라서 왜, 다음에 내 쿼리를 변환 :

,
HAVING interests IN '(7)' 

어떻게하면 (7) 주위의 따옴표를 제거 할 수 있습니까?

+0

'HAVING 이익에서

은 '(7)''- 그 오류 아니다. 질의는 코드에서 지정한 ID 목록 **에 대한 것입니다. 어떤 "오류"(또는 예기치 않은 동작)를 실제로보고 있습니까? –

+0

문제는 '(7)'주위의 따옴표입니다. 거짓과 함께 PaulD의 대답을 사용하여 해결되었습니다. – Dennis

답변

0

탈출을 해제 할 수 있습니다.

If you are using a database that CodeIgniter escapes queries for, you can prevent escaping content by passing an optional third argument, and setting it to FALSE.

$this->db->having('user_id', 45); // Produces: HAVING `user_id` = 45 
$this->db->having('user_id', 45, FALSE); // Produces: HAVING user_id = 45 

하나 개의 인수로 하나의 배열을 전달할 때이를 구현,하지만 당신은 추가 FALSE 매개 변수를 필요로하는 방법 확실하지. IN http://www.codeigniter.com/user_guide/database/query_builder.html