Welcome Guest, Not a member yet? Register   Sign In
Group By Month/Year Within Array
#1

[eluser]Jay Logan[/eluser]
I'm trying to put together a page that sorts "meets" and groups them together by month & year. IE:

Jan 2009

- Meet 1
- Meet 2
- Meet 3


Feb 2009

- Meet 4
- Meet 5


March 2009
-Meet 6


Etc. etc.

So far, I have been able to produce a page showing all meets ordered by date (from MySQL). But I'm not sure how to tackle this issue. Do I do it in the model? I'm assuming I need to make a new key for each group. Still new to programming. Any help would be appreciated. Here is my current code.

Code:
function get_all_meets()
    {
        $this->db->select();
        $this->db->from('meets');
        $this->db->where('hide', '0');
        $this->db->orderby('date');
        $query = $this->db->get();
        $result = $query->result_array();
        $i = 0;
        foreach ($result as $meet) {
            $this->db->select();
            $this->db->from('meet_events');
            $this->db->where('meet_id', $meet['id']);
            $query = $this->db->get();
            $events = $query->result_array();
            $result[$i++]['event_count'] = count($events);
        }
        return $result;
    }


Messages In This Thread
Group By Month/Year Within Array - by El Forum - 03-13-2009, 03:06 PM
Group By Month/Year Within Array - by El Forum - 03-13-2009, 03:21 PM
Group By Month/Year Within Array - by El Forum - 03-13-2009, 04:22 PM
Group By Month/Year Within Array - by El Forum - 03-13-2009, 04:26 PM
Group By Month/Year Within Array - by El Forum - 03-13-2009, 04:33 PM
Group By Month/Year Within Array - by El Forum - 03-14-2009, 05:46 AM
Group By Month/Year Within Array - by El Forum - 03-14-2009, 06:29 AM
Group By Month/Year Within Array - by El Forum - 03-14-2009, 07:13 AM
Group By Month/Year Within Array - by El Forum - 03-16-2009, 08:42 AM
Group By Month/Year Within Array - by El Forum - 03-16-2009, 09:17 AM
Group By Month/Year Within Array - by El Forum - 03-16-2009, 11:48 AM
Group By Month/Year Within Array - by El Forum - 03-16-2009, 12:14 PM
Group By Month/Year Within Array - by El Forum - 03-16-2009, 01:47 PM



Theme © iAndrew 2016 - Forum software by © MyBB