This is my datatable model which combines all the tables that i need, and the console found an error in this code where VehicleNo is ambiguous.
I also need to order by ApplicationNo and distinct the ApplicationNo so that it wont duplicate other table
private function _get_datatables_query(){
if($this->input->post('Status'))
{
$this->db->where('Status', $this->input->post('Status'));
}
$this->db->select('*');
//$this->db->distinct('ApplicationNo');
$this->db->from($this->table);
$this->db->distinct();
$this->db->join('user', 'user.userId = loanapplication.userId');;
$this->db->join('collateraldetails', 'collateraldetails.ApplicationNo = loanapplication.ApplicationNo');
$this->db->join('vehicleinformation', 'vehicleinformation.VehicleNo = collateraldetails.VehicleNo');
$this->db->join('loanrequest', 'loanrequest.ApplicationNo = loanapplication.ApplicationNo');
$this->db->join('loanapproval', 'loanapproval.RequestNo = loanrequest.RequestNo');
$this->db->join('paymentdetails', 'paymentdetails.ApplicationNo = loanapplication.ApplicationNo');
$this->db->join('loanpayment', 'loanpayment.PaymentId = paymentdetails.PaymentId');
//echo $this->db->last_query();exit;
$i = 0;
foreach ($this->column_search as $item) // loop column
{
if($_POST['search']['value']) // if datatable send POST for search
{
if($i===0) // first loop
{
// open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
$this->db->group_start();
$this->db->like($item, $_POST['search']['value']);
}
else
{
$this->db->or_like($item, $_POST['search']['value']);
}
if(count($this->column_search) - 1 == $i) //last loop
$this->db->group_end(); //close bracket
}
$i++;
}
if(isset($_POST['ApplicationNo'])) // here order processing
{
$this->db->order_by($this->column_order[$_POST['ApplicationNo']['0']['column']], $_POST['ApplicationNo']['0']['dir']);
}
else if(isset($this->ApplicationNo))
{
$ApplicationNo = $this->ApplicationNo;
$this->db->order_by(key($ApplicationNo), $ApplicationNo[key($ApplicationNo)]);
}}