AND代码点火器的活动记录

时间:2014-10-01 09:08:16

标签: php mysql codeigniter

如何在codeigniter中的活动记录中编写此查询。

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

3 个答案:

答案 0 :(得分: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');

答案 1 :(得分:1)

如果没有数组,你可以尝试将条件分开;创建AND操作。

      $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 :(得分:0)

从codeigniter教程:我的查询使用以下查询:

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