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
Post a Comment