2012-10-19 11 views
1

코드 니터에서 (조건 1 AND 조건 2) 또는 (조건 3 AND 조건 4) 할 수 있습니까?Codeigniter AND AND AND

$this->db->where(condition1 - condition2); 
$this->db->or_where(condition3 - condition4); 

하지만은 다음과 같습니다 :

나는 시도 (조건 1과 조건 2) OR (조건 3 또는 condition4)

+0

솔직히 나는 그것을 찾았을 때까지 Codeigniter에서 쿼리를 그룹화하는 직접적인 방법이 없다는 것을 알지 못했습니다. 나는 꽤 오랫동안 CI에 대해 [Datamapper ORM] (http://datamapper.wanwizard.eu/)을 사용 해왔다. 언젠가는 당신이 그것을 즐길 수 있다고 생각하고 (그룹화 절은 쉽다) 체크 아웃했다. –

답변

3

은 그냥 어디

이 여전히 의지에 그것을 밖으로 쓰기 데이터를 이스케이프 처리하므로 or_where 메소드를 속일 필요가 없습니다.

1

다음과 같이 시도해보십시오 :::::?

$this->db->where(COND1); 
$this->db->where(COND2); 
$this->db->or_where(COND3); 
$this->db->where(COND4); 
0

그냥과 같이 정상적인 쿼리를 사용 :

$query="SELECT * 
FROM table1 INNER JOIN table2 on table1.col=table2.col 
WHERE (table1.whatever=? AND table1.hello=?) OR (table2.foo=? AND table2.pizza=?) 
LIMIT 1"; 
$params=array(); 
$params[]='whatever'; 
$params[]='world'; 
$params[]='bar'; 
$params[]='cheese'; 


$result=$this->db->query($query,$params); 
$result=$result->result_array(); 
print_r($result); 
1
$first="(COND1 AND COND2)"; 
$second= "(COND3 AND COND4)"; 

$query=$this->db->where($first)->or_where($second)->get(); 
1

네 것이 가능 편의상 변수 하나

$where ="(condition 1 AND condition2) OR (condition3 AND condition4)"; 
$this->db->where($where); 
0

하는 경우에 사용하기 원하는 조건을 가지고 PHP5를 사용하면 다음 코드가 문제를 해결할 것입니다.

$this->db->select("*") 
->where("condition_1 && condition_2") 
->or_where("condition_3 && condition_4"); 

또는 다음 코드를 사용해도됩니다.

$this->db->where("condition_1 "); 
$this->db->where("condition_2"); 
$this->db->or_where("condition_3 "); 
$this->db->where("condition_4 ");