0

Problem 1:

Looking to display some events GROUPED as follows:

Year
Month
event details here

The database has the following structure:

    event_year | event_month | event_day | event_name | event_description
    2013       | 11          | 08        | Name 1     | Desc 1
    2013       | 12          | 31        | Name 2     | Desc 2
    2014       | 02          | 14        | Name 3     | Desc 2
    2014       | 03          | 25        | Name 4     | Desc 4

I would like it to display as follows:

    2013
         November
         08/11/2013 - Name 1: Desc 1

         December 
         31/12/2013 - Name 2: Desc 2

    2014
         February
         14/02/2014 - Name 3: Desc 3

         March
         25/03/2014 - Name 4: Desc 4

Problem 2:

There are also past events on the table, and of course we only want to display upcoming events. How would I solve that issue? As of now, I managed to display all events, which works quite well, and I also figured how to sort them by year and months, but it only gives me a list of all events, but not grouped.

Here is the code out of the model:

    function getEvents($limit = 20, $offset = 0) {
    $this->db->select('*');
    $this->db->from('events_posts');
    $this->db->limit($limit, $offset);
    $this->db->order_by('event_year', 'desc');      
    $b = $this->db->get()->result();
    return $b;
}

function getAllEvents() {
    $this->db->select('*');
    $this->db->from('events_posts');    
    $b = $this->db->get();
    return $b;
}

Here is the controller:

    $events = $this->events_model->getEvents($config['per_page'], $from);
    $this->outputData['events'] = $events;
    $this->load->view('events/index',$this->outputData);

and my views page:

    <?php foreach($events as $event) { ?>
    <a href="<?php echo site_url('events/view/' . $event->id); ?>"><h2><b><?php          
    echo $this->lang->line('Event:'); ?> <?php echo $event->title ?></b></h2></a>
    <?php echo $event->descriptions ?>
    <?php echo $event->event_day ?>/<?php echo $event->event_month ?>/<?php echo $event->event_year ?> a las <?php echo $event->event_hour ?>:<?php echo $event->event_min ?> horas     
<?php } ?>
4

0 回答 0