2014-10-01 58 views
1

我該如何在codeigniter中的活動記錄中寫入此查詢。代碼點火器中AND的有效記錄

SELECT * FROM `post_ads` WHERE `dates` >= '2014-09-20' AND `dates` <= '2014-09-22' ORDER BY `dates` ASC 

我試過這個代碼,但給了一個空的數組。

$where = "DATE(dates) BETWEEN '2014-09-20' AND '2014-09-22'"; 
    $query = $this->db->where($where)->get('post_ads'); 
    return $query->result(); 
+0

那麼你有什麼嘗試? – Shaeldon 2014-10-01 09:10:45

+3

沒有任何嘗試? https://ellislab.com/codeigniter/user-guide/database/active_record.html – Ghost 2014-10-01 09:11:14

+0

$ where =「DATE(日期)BETWEEN'2014-09-20'和'2014-09-22'」; $ this-> db-> where($ where) - > get('post_ads'); – user254153 2014-10-01 09:12:58

回答

1

只要沒有數組,你可以嘗試一下:我的查詢與下面的查詢工作這裏的條件相隔;創建和操作。

 $this->db->where('dates >=', 2014-09-20); 
     $this->db->where('dates <=', 2014-09-22); 
     $this->db->order_by("dates", "asc"); 
     $query = $this->db->get('post_ads'); 
     return $query->result(); 
2

簡單地重複了兩遍像這樣:

$this->db->select(); 
$this->db->from('post_ads'); 
$this->db->where('dates','2014-09-20'); 
$this->db->where('dates','2014-09-22'); 
$this->db->order_by('dates'); 
+0

謝謝。我工作了 – user254153 2014-10-01 09:27:18

0

從笨教程:

$array = array('dates >=' => $to, 'dates <=' => $from); 
$this->db->where($array); 
$this->db->order_by("dates", "asc"); 
$query = $this->db->get('post_ads'); 
return $query->result();