2015-10-12 6 views
5

Sto cercando di creare la seguente dichiarazione:valore non è NULL in CodeIgniter

select * from donors where field is NOT NULL; 

Con CodeIgniter, il mio codice è simile al seguente:

$where = ['field' => NULL]; 
$this->db->get_where('table', $where); 
+2

Possibile duplicato di [clausola CodeInizio Where] (http://stackoverflow.com/questions/10109047/codeigniter-where-clause) – vhu

risposta

29

quando si vede documentation È possibile utilizzare $this->db->where() con terzo parametro impostato su FALSE per non uscire dalla query. Esempio:

$this->db->where('field is NOT NULL', NULL, FALSE); 

Oppure è possibile utilizzare query string personalizzato come questo

$where = "field is NOT NULL"; 
$this->db->where($where); 

Così il vostro generatore di query sarà simile a questa:

$this->db->select('*'); 
$this->db->where('field is NOT NULL', NULL, FALSE); 
$this->db->get('donors'); 

O

$this->db->select('*'); 
$where = "field is NOT NULL"; 
$this->db->where($where); 
$this->db->get('donors'); 
1

Prova questo:

$this -> db -> get_where('donors', array('field !=' => NULL));