Welcome Guest, Not a member yet? Register   Sign In
how to make a date based blog archieve in ci3 using query builder
#2

(This post was last modified: 02-27-2015, 12:03 PM by Wouter60.)

Try this:
Code:
$this->db->select('DATE_FORMAT(datetime,"%Y%m") AS month',NULL,FALSE)
->select('COUNT(id) AS num_per_month')
->from('posts')
->group_by('month');
$query = $this->db->get()->result_array();
Assuming that your table name is 'posts' and this table has a field called 'datetime'.
The result is an array with rows. Each row has the columns 'month' and 'num_per_month'.
E.g.: $r['month'] => '201501' stands for: January 2015.
Reply


Messages In This Thread
RE: how to make a date based blog archieve in ci3 using query builder - by Wouter60 - 02-27-2015, 11:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB