2012-03-30 13 views
10

Üç koşullu bir tablodan bir Codeigniter select sorgusu istiyorum.Codeigniter AND ve OR koşuluyla sorguyu seç

1. wrk_fld_exc = 140 
2. wrk_cs_sts = Open 
3. wrk_dlvrd_sts = Delivered OR wrk_cl_sts = Success 

Üçüncü koşul bir VE koşul OR OR durumunu içerir. İlk ve ikinci Ve durumdur.

cevap

21

Böyle bunu kodlayabiliriz:

 $this->db->where('wrk_fld_exc',140); 
     $this->db->where('wrk_cs_sts','open'); 
     $where = '(wrk_dlvrd_sts="open" or wrk_cl_sts = "Success")'; 
     $this->db->where($where); 
1

bu

$this->db->where('wrk_fld_exc',140); 
$this->db->where('wrk_cs_sts','open'); 
$this->db->where('wrk_dlvrd_sts ','Delivered'); 
$this->db->or_where('wrk_cl_sts','Success'); 
0
$this->db->where('wrk_fld_exc',140); 

$this->db->where('wrk_cs_sts','open'); 

$where = '(wrk_dlvrd_sts="open" or wrk_cl_sts = "Success")'; 

$this->db->where($where); 
0
$this->db->select("*"); 
    $this->db->from("table_name"); 
    if($condition1 != ''){ 
     $this->db->where('wrk_fld_exc', 140); 
    } 
    if($condition2 != ''){ 
     $this->db->where('wrk_cs_sts ', open); 
    } 
    //You can limit the results 
    $this->db->limit(5); 
    $q = $this->db->get(); 
    return $q->result(); 

gibi Bu CodeIgniter'daki bu şekilde uygulayabileceğiniz sorgunun temel yapıdır. Gerekirse koşulları ekleyebilirsiniz.

4

CodeIgniter VEYA Baba kullanmak

$this->db->or_where('wrk_cl_sts','Success'); 

sorguda VE nereye iki defa fıkra kullanımı $this->db->where('');

kendi sözdizimi kullanır