[eluser]yacman[/eluser]
OP I recommend that you start with the sql, then build an active record query around it, or
just use the sql and do a $this->db->query();
e.g. say this returns your count correctly from the sql command line.
Code:
SELECT count(id) as total
FROM item_history
where date_created >= '2012-09-01' and date_created <= '2012-09-30';
Cronix has provided you with the correct active record statement to produce this:
Code:
$this->db->select('COUNT(id) as total',false);
$this->db->where('date_created >=', $startDate);
$this->db->where('date_created <=', $endDate);
$query = $this->db->get('item_history');
$total = 0;
//This is a grouped result, so there will only be one row returned.
if (!empty($query) && $query->num_rows() > 0) {
//Reference the result sets first rows column named 'total'.
$total = $query->row()->total;
$query->free_result();
}
echo "Total Rows {$total}";
If you just have a sql query you know works, then use it:
Code:
$sql = "SELECT count(id) as total
FROM item_history
where date_created >= '{$startDate}' and date_created <= '{$endDate}'";
$query = $this->db->query($sql);
...