php - Codeigniter - join() returns only one "first table" -


i have struggle codeigniter active record in model.

problem query returns 1 table, joined table missing?

    $this->db->select("page.id, page.title, category.title");     $this->db->from('page');     $this->db->join('category','page.id_category = category.id');     $query = $this->db->get();      return $query->result_array(); 

you need give unique aliases query array index unique can't have 2 values on same index query title become index of array has records try below query,your current results in array form like

array( [0] => array( ['id'] => 1, ['title'] => test page ) [1] => ... ) 

because column name title same in both joined tables,you can't have array below 1 with 2 values on same index

array( [0] => array( ['id'] => 1, ['title'] => test page, ['title'] => test cat /* wrong index */ ) [1] => ... ) 

query

$this->db->select("page.id, page.title page_title, category.title cat_title"); $this->db->from('page'); $this->db->join('category','page.id_category = category.id'); $query = $this->db->get(); 

so resultant array

array( [0] => array( ['id'] => 1, ['page_title'] => test page, ['cat_title'] => test cat, ) [1] => ... ) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -