2012-01-13 5 views
2

하이 CodeIgniter의 다른 컬럼에없는 하나 개의 컬럼에서 레코드를 얻고, 난이내가 CodeIgniter를 사용하고

enter image description here

PreferenceID 값이없는 경우에는 내가 모든 레코드를 얻으려면 같은 테이블이하는 방법 PreferenceParentID

이 경우 나는 또한 EntityID과 함께 fitering 테이블입니다. 및 PreferenceParentID 두 경우 모두 PreferenceParentID에없는

Couture , Denims 

PreferenceID 때문에 내 결과가 될 말아야 entityID53

에 의해 != 0

가정 해 전 필터가 될 말아야. 나는 where_not_in()으로 시도했지만 할 수 없었습니다. 이 내 쿼리

입니다

도와주세요

$table = $this->mastables['shop_profile_preferences']; 
    $this->db->select('a.ProfilePreferenceID'); 
    $this->db->from($table." as a"); 

    $where2 = "(SELECT a.PreferenceParentID FROM ".$table.")"; 
    $this->db->where_not_in('a.PreferenceID', $where2); 

    $this->db->where("a.EntityID",$shop_id); 
    $this->db->where('a.PreferenceParentID !=',0); 

    $query=$this->db->get(); 

    if($query->num_rows()>0) 
    { 
     return $query->result_array(); 
    } 
    else 
    { 
     return FALSE; 
    } 

내 쿼리의 결과는

Array 
(
    [0] => Array 
     (
      [ProfilePreferenceID] => 274 
     ) 

    [1] => Array 
     (
      [ProfilePreferenceID] => 275 
     ) 

    [2] => Array 
     (
      [ProfilePreferenceID] => 276 
     ) 

) 

어떻게 제대로 where_not_in()을 사용하는 것입니다. 거기에 다른 방법이 있습니다. 제발 도와주세요 ..... 미리 감사드립니다.

UPDATE

$table = $this->mastables['shop_profile_preferences']; 
    $this->db->select('a.ProfilePreferenceID,a.ProfilePreferenceValue'); 
    $this->db->from($table." as a"); 

    $this->db->where('a.PreferenceParentID !=',0); 
    $this->db->where('a.PreferenceID NOT IN (SELECT a.PreferenceParentID FROM '.$table.')', NULL, FALSE); 
    $this->db->where("a.EntityID",$shop_id); 

    $query=$this->db->get(); 

    if($query->num_rows()>0) 
    { 
     return $query->result_array(); 
    } 
    else 
    { 
     return FALSE; 
    } 

답변

4

당신이 할 수 CodeIgniter의의 where_not_in()와. 두 번째 인수는 배열이고 그와 같은 문자열이 아니기 때문에.

대신 할 수있는 일은 일반적인 where() 방법을 사용하는 것입니다.

당신이 궁금해하는 경우
$this->db->where('a.PreferenceID NOT IN (SELECT a.PreferenceParentID FROM `table_name`)', NULL, FALSE); 

은, 위의 코드에서 세 번째 인수는 역 따옴표로 필드와 테이블 이름을 보호하려는에서 CodeIgniter를 방지하는 것입니다.

+0

mm 여전히 작동하지 않습니다. 다시 연결됩니다. –

+0

내 쿼리를 $ this-> db-> where ('a.PreferenceID NOT IN (SELECT a.PreferenceParentID FROM'. $ table. ')', NULL, FALSE)로 변경했습니다. –

+0

@KanishkaPanamaldeniya 업데이트 된 코드로 게시물을 업데이트 할 수 있습니까? –

관련 문제