2012-08-11 2 views
0

I (CodeIgniter의 프레임 워크를 사용) ExpressionEngine에 다음과 같은 조건이 있습니다CodeIgniter의 :에 추가 where 절

if ($group_id !== '') 
    { 
     $this->db->where("members.group_id", $group_id); 
    } 

더 낫다고가 추가 조건을 추가 할 어디 (는 AND), 어떻게 할 수있는 그 나는 이것을한다? 새 $this->db->where('my_field', $my_value)을 추가합니까? 아니면 어떻게?

답변

2

당신은 짐작했습니다.

if ($group_id !== '') 
{ 
    $this->db->where("members.group_id", $group_id); 
    $this->db->where('my_field', $my_value); 
} 

확인 CodeIgniter의 문서 http://codeigniter.com/user_guide/database/active_record.html 그것은 좋다. 당신이 많은 테이블과 매우 복잡한 쿼리를 작성 결국 한 번

$data = array('name' => $_POST['name'], 'lname' => $_POST['lname']); 
$sql = "select table where name = ? and lname = ?"; 
$this->db->query($sql, $data); 

조인이되고 내가 그것을 쓰는 것을 선호 이유가 있기 때문에 :

0
// if (is_numeric($group_id) && $group_id > 0) 
if ($group_id) 
{ 
    $this->db->where("members.group_id", $group_id); 
    $this->db->where('my_field', $my_value); 
    // $this->db->where('my_field >=', $my_value); 
    // $this->db->where('my_field <', $my_value); 
} 
0

는 내가 뭘하면 같은 쿼리를 쓰는 것입니다 활성 레코드 쿼리를 읽는 것은 정말 어렵습니다.

0

야아 ..... u는이 시도 할 수 있습니다 :

if ($group_id !== '') 
{ 
    $this->db->where("members.group_id", $group_id); 
    $this->db->where('my_field', $my_value); 
} 

이 유도 사용할 수 있습니다

$this->db->or_where('my_field',$my_value);