2017-01-11 43 views
0

我在模型Where子句是模糊的笨模型

function get_datatables() 
{ 
    $this->_get_datatables_query(); 
    // Join Table 
    $this->db->join('test_1_category','test_1_category.category_id = test_1_product.category_id','RIGHT');     

    if($_POST['length'] != -1) 
    $this->db->limit($_POST['length'], $_POST['start']); 
    $query = $this->db->get(); 
    return $query->result(); 
} 

enter image description here

有辦法解決的代碼?

+0

你到底想要產生什麼輸出?是否像類別的父母子女? –

+0

這兩個表都有相同的字段名稱,這就是爲什麼你會得到該錯誤。使用別名來避免這種情況。 –

+0

雅,在產品類別 –

回答

0

在這裏,您正在爲test_1_product正確執行test_1_category.But的編碼爲test_1_category.category_id = test_1_product.category_id。因此,在獲取行時顯示模糊錯誤,因爲RIGHT JOIN關鍵字返回右表(table2)中的所有行,並在左表(table1)中匹配行。在沒有匹配的情況下,左側的結果爲NULL。所以試試像這樣...

function get_datatables() 
{ 
    $this->_get_datatables_query(); 
    // Join Table 
    $this->db->join('test_1_category','test_1_product.category_id = test_1_category.category_id','RIGHT'); //query was ambiguous here     

    if($_POST['length'] != -1) 
    $this->db->limit($_POST['length'], $_POST['start']); 
    $query = $this->db->get(); 
    return $query->result(); 
}