2015-04-19 154 views
0

我正在嘗試將查詢中的代碼更新爲codeigniter活動記錄。用codeigniter活動記錄連接表

這這裏是我的舊代碼

public function get_categories($parent_id = 0) { 

    $language_id = "1"; 

    $query = $this->db->query("SELECT * FROM " . $this->db->dbprefix . "category c LEFT JOIN " . $this->db->dbprefix . "category_description cd ON (c.category_id = cd.category_id) LEFT JOIN " . $this->db->dbprefix . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE c.parent_id = '" . (int)$parent_id . "' AND cd.language_id = '" . (int)$language_id . "' AND c2s.store_id = '" . (int)$language_id . "' AND c.status = '1' ORDER BY c.sort_order, LCASE(cd.name)"); 

    return $query->result_array(); 
} 

,我試圖將其更新爲新的代碼下面

這個問題我有是不是通過ID得到正確的結果。並且由於升級到CI-3舊代碼不起作用。

public function get_categories($parent_id = 0) { 
    $this->db->select('*'); 
    $this->db->from('category'); 
    $this->db->join('category_description', 'category_description.category_id = category.category_id', 'left'); 
    $query = $this->db->get(); 

    if ($query->num_rows() > 0) { 
     return $query->result_array(); 
    } else { 
     return false; 
    } 
} 

如何正確使用codeigniter連接。能夠讓我的代碼工作。

回答