I have this controller which displays my events by event_date the date format is like 'Y-m-d'
Question Is there away that I could display the events for this month first in the list then the rest of the events after?
Model
public function getevents($filter = array()) {
$this->db->limit($filter['limit'], $filter['start']);
$this->db->order_by($filter['order'], $filter['sort']);
$query = $this->db->get('event');
return $query->result_array();
}
Controller
<?php
class Events extends Admin_Controller {
private $error = array();
public function __construct() {
parent::__construct();
$this->load->model('admin/event/events_model');
$this->load->library("pagination");
}
public function index() {
$this->getlist();
}
public function getlist() {
$this->document->set_title('Events');
$data['heading_title'] = 'Events';
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => 'Dashboard',
'active' => '',
'href' => site_url('admin/dashboard')
);
$data['breadcrumbs'][] = array(
'text' => 'Events',
'active' => 'active',
'href' => site_url('admin/events')
);
if ($this->input->get('order')) {
$order = $this->input->get('order');
} else {
$order = 'event_date';
}
if ($this->input->get('sort')) {
$sort = $this->input->get('sort');
} else {
$sort = 'desc';
}
if ($this->input->get('limit')) {
$limit = $this->input->get('limit');
} else {
$limit = 5;
}
if ($this->uri->segment(3)) {
$page = $this->uri->segment(3);
} else {
$page = 0;
}
$config["base_url"] = base_url('admin/events');
$config["total_rows"] = $this->events_model->total_count();
$config["per_page"] = $limit;
$config["uri_segment"] = 3;
$config['use_page_numbers'] = FALSE;
$config['full_tag_open'] = '<nav><ul class="pagination">';
$config['full_tag_close'] = '</ul></nav>';
$config['num_tag_open'] = '<li class="page-item"><span class="page-link">';
$config['num_tag_close'] = '</span></li>';
$config['cur_tag_open'] = '<li class="page-item active"><span class="page-link">';
$config['cur_tag_close'] = '<span class="sr-only">(current)</span></span></li>';
$config['next_tag_open'] = '<li class="page-item"><span class="page-link">';
$config['next_tagl_close'] = '<span aria-hidden="true">»</span></span></li>';
$config['prev_tag_open'] = '<li class="page-item"><span class="page-link">';
$config['prev_tagl_close'] = '</span></li>';
$config['first_tag_open'] = '<li class="page-item"><span class="page-link">';
$config['first_tagl_close'] = '</span></li>';
$config['last_tag_open'] = '<li class="page-item"><span class="page-link">';
$config['last_tagl_close'] = '</span></li>';
$this->pagination->initialize($config);
$filter = array(
'order' => $order,
'sort' => $sort,
'limit' => $limit,
'start' => $page
);
$data['events'] = array();
$events = $this->events_model->getevents($filter);
foreach ($events as $event) {
$button = array(
'type' => 'button',
'class' => 'btn btn-danger',
'content' => '<i class="fa fa-trash" aria-hidden="true"></i> Remove',
'data-toggle' => 'model',
'data-target' => '#event_model',
'data-id' => $event['event_id']
);
$data['events'][] = array(
'event_title' => $event['event_title'],
'event_date' => date('l dS F Y', strtotime($event['event_date'])),
'href' => anchor('admin/events/update/' . $event['event_id'], 'Edit', array('class' => 'btn btn-primary')),
'delete' => form_button($button)
);
}
$data["pagination_links"] = $this->pagination->create_links();
$data['header'] = Modules::run('admin/common/header/index');
$data['column_left'] = Modules::run('admin/common/column_left/index');
$data['footer'] = Modules::run('admin/common/footer/index');
$data['topnavbar'] = Modules::run('admin/common/topnavbar/index');
$this->load->view('template/event/getlist', $data);
}
}