Question

I have 3 tables and I want to join them. If these three has one field similar to each other, that would be easy. The problem is, table1 and table2 has one similar field, table2 and table3 has another similar field, but there's no similar field at all that would connect table1 and table3. I tried joining them using the code below, but it doesn't work. I got an error that field "branch_name" is undefined:

    $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');

Is there any solution to this?

Était-ce utile?

La solution

Try putting in $this->output->enable_profiler(TRUE) in your controller to see the SQL that was executed. It's easier to troubleshoot that way. I will normally copy the SQL that was executed and troubleshoot it in MySQL client to see what went wrong.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top