How can I write this query in CodeIgniter's query builder?
SELECT *
FROM `post_ads`
WHERE `dates` >= '2014-09-20'
AND `dates` <= '2014-09-22'
ORDER BY `dates` ASC
I tried this code but gave an empty array.
$where = "DATE(dates) BETWEEN '2014-09-20' AND '2014-09-22'";
$query = $this->db->where($where)->get('post_ads');
return $query->result();
Simply without array you can try out this where condition separated by ; creates AND operation.
$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();