Welcome Guest, Not a member yet? Register   Sign In
How to join three or more tables?

I want to create an array with data from three tables.

How would I go about doing that using the active record class?

It works with two tables easily but when I add anymore tables I get some errors.

Can someone place a simple example?

Here is a join over three tables:

device <-> device_type <-> lang_device_type

function getDevicesByUnitId($unit_id)
        $this->db->select('*, ldt.name as typename, d.name as devicename');
        $this->db->orderby('d.name', 'asc');
        $this->db->join('device d', 'd.device_type_id = dt.device_type_id', 'inner');
        $this->db->join('lang_device_type ldt', 'ldt.device_type_id = dt.device_type_id', 'inner');
        $this->db->where('d.unit_id', $unit_id);
        $this->db->where('ldt.lang_id', $this->session->userdata('lang'));
        return $this->db->get('device_type dt');

Theme © iAndrew 2016 - Forum software by © MyBB