I built a program and noticed that in 2018 the sorting is not correct. I fixed it so it would show 2018 first but it still having an issues sorting correctly now it is showing example 1/02/2018 then 1/03/218 and so on, but I need it to show 1/03/2018 then 1/2/2018 then all of 2017 after. Here is my partial code for the model if anymore code is needed I will add it.
Model.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class visitor_log_model extends CI_Model {
var $table = 'visitor_log_list';
var $column = array('date','name','vendor','department','contact_person','expected_arrival_time'); //set column field database for order and search
var $order = array('id' => 'desc'); // default order
public function __construct()
{
parent::__construct();
$this->load->database();
}
//gets the gets all the records from the database
private function _get_datatables_query()
{
$this->db->from($this->table);
$this->db->order_by("date", "asc");
$this->db->order_by("expected_arrival_time", "asc");
$i = 0;
foreach ($this->column as $item) // loop column
{
if($_POST['search']['value']) // if datatable send POST for search
{
if($i===0) // first loop
{
$this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
$this->db->like($item, $_POST['search']['value']);
}
else
{
$this->db->or_like($item, $_POST['search']['value']);
}
if(count($this->column) - 1 == $i) //last loop
$this->db->group_end(); //close bracket
}
$column[$i] = $item; // set column array variable to order processing
$i++;
}