2014-10-01 86 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();