2012-03-30 10 views
10

Voglio una query di selezione CodeIndect da una tabella con tre condizioni in.Codeigniter seleziona query con AND e OR condition

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

La terza condizione è una condizione AND contiene condizione OR. Primo e secondo è condizione.

risposta

21

è possibile codificare in questo modo:

 $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

Ti piace questa

$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(); 

Questa è la struttura di base della query è possibile implementare in questo modo in CodeIgniter. È possibile aggiungere condizioni se richiesto.

4

codeigniter utilizza la propria sintassi per O Natale nella query

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

da usare e in cui l'uso clausola $this->db->where(''); due volte