While you are doing SELECT * ( Why is this a bad idea? ), You do not need to specify tables with a select() call. It will select all fields by default.
$this->db->from('works_image', 'works'); $this->db->join('works', 'works.id = works_image.id_work'); $result = $this->db->get();
Should work fine.
Instead of what you really have to do, itβs exactly what fields you need:
$this->db->select('works_image.id, works_image.name, works_image.id_work, works.id, works.name'); // (or whichever fields you're interested in) $this->db->from('works_image', 'works'); $this->db->join('works', 'works.id = works_image.id_work'); $result = $this->db->get();
Thus, you can be sure that (a) you are not extracting unnecessary data from your database and (b) your code will not be interrupted if / when you change the database schema.
pix0r source share