2013-08-01 38 views
0

我有3個表,我想加入它們。如果這三個領域有一個類似的領域,那很容易。問題是,table1和table2有一個類似的字段,table2和table3有另一個類似的字段,但是沒有類似的字段可以連接table1和table3。我嘗試使用下面的代碼加入他們,但它不起作用。我得到一個錯誤的那場「branch_name」未定義:在codeigniter中加入更多的2個表,沒有公共字段

$this->db->select('r.*,       
         b.id as branch_id,       
         b.name as branch_name'); 
    $this->db->join('users_branches AS ub', 'ub.user_id = r.user_id'); 
    $this->db->join('branches AS b', 'b.id = ub.branch_id'); 

    $this->db->where('payroll_period_id',$payroll_period_id);   
    return $this->db->get('dtr r'); 

是否有任何解決這個?

回答

0

嘗試在您的控制器中放入$this->output->enable_profiler(TRUE)以查看已執行的SQL。以這種方式進行故障排除更容易。我通常會將執行的SQL複製並在MySQL客戶端中進行故障排除,以查看出了什麼問題。

相關問題