Codeigniter: Select from multiple tables

前端 未结 7 1805
闹比i
闹比i 2020-12-30 11:23

How can I select rows from two or more tables?

I\'m setting default fields for a form, and I need values from two tables...

My current code reads:

         


        
7条回答
  •  梦毁少年i
    2020-12-30 11:56

    I think the question was not so much about joins as how to display values from two different tables - the User Guide doesn't seem to explain this.

    Here's my take:

        $this->db->select('u.*, c.company, r.description');
        $this->db->from('users u, company c, roles r');
        $this->db->where('c.id = u.id_company');
        $this->db->where('r.permissions = u.permissions');
        $query = $this->db->get();
    

提交回复
热议问题