DataTable模型错误

时间:2017-07-14 18:28:12

标签: mysql codeigniter datatables

这是我的数据表模型,它结合了我需要的所有表,并且控制台在此代码中发现了一个错误,其中VehicleNo不明确。

enter image description here

我还需要通过ApplicationNo订购并区分ApplicationNo以便它不会复制其他表

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)]);
}}

2 个答案:

答案 0 :(得分:1)

您在多个表中有列VehicleNo。您加入了它并且没有指定列VehicleNo从哪个表用于where条件。你得到这个错误。

您需要指定vehicleinformationVehicleNo。此外,你应该使用表别名,这是一个很好的做法。

答案 1 :(得分:1)

这是不明确的,因为你所指的是混淆,在你的表中使用别名。