2012-02-16 75 views
0

我有兩個表,一個列出產品,一個列出產品類型。我試圖從產品表中調用所有內容,然後調用tCategory與產品表上的類別匹配的產品類型表中的所有內容。當我在產品類型中只有一行匹配的情況下工作,但如果有更多行,它會從產品再次調用所有數據。以下是我有:Codeigniter有效記錄加入

$this->db->from('product'); 
    $this->db->where('perm_name', $this->uri->segment(2)); 
    $this->db->join('product_type', 'product_type.tCategory = product.type'); 
    $query = $this->db->get(); 

關於如何解決此問題的任何想法?

回答

1

你需要指定你想如果你需要一個特定的連接類型,從user_guide使用,通過使用第三個參數

$this->db->join();

可以通過第三 參數指定它是什麼JOIN的功能。選項有:左側,右側,外側,內側, 左側外側,右側外側。

代碼示例

$this->db->join('comments', 'comments.id = blogs.id', 'left'); 

// Produces: LEFT JOIN comments ON comments.id = blogs.id