2013-05-22 54 views
2

我正在使用CodeIgniter形成一個不能正常工作的簡單查詢。Codeigniter比較大於或小於同一字段的值的ID

我試圖獲取一個字段,其中action_ id大於1而小於4

舉例如下:

$this->db->where('newsfeeds.action >', '1');

$this->db->where('newsfeeds.action <', '4');

但是我不知道如果因爲我引用了兩次相同的字段,CodeIgniter不知道如何運行查詢。

回答

1

試試這個:

$this->db->where('newsfeeds.action >', 1); 

$this->db->where('newsfeeds.action <', 4); 

或者,如果WHERE條件有靜態值,你可以直接做:

$this->db->where('newsfeeds.action > 1'); 

$this->db->where('newsfeeds.action < 4'); 

並查看查詢使用:

echo $this->db->last_query(); 
0

您可以使用多個條件$this->db->where

$where= array('newsfeeds.action >' =>1, 'newsfeeds.action <' => 4) 
$this->db->where($where); 

參考Active Record

0

看到這個嘗試這一個SQL發送到他的功能。

$this->db->query($sql);

0

您可以通過包含整個字符串使用WHERE條件像

$where = "name='Joe' AND status='boss' OR status='active'"; 

$this->db->where($where); 

希望這會有所幫助。

相關問題