I have a relational database in this format
Table: posts
Columns: post_id,post_title,post_content
Table: categories
Columns: category_id,category_name
Table: posts_categories
Columns: post_id,category_id
Posts can have multiple categories so i store them in posts_categories using post and category id, when i get results from database using below query, it just display the last category, Is it possible to display all categories otherwise i have to run a separate query, here my code.
$this->db->select("p.*,pc.*,c.*");
$this->db->where('post_id', $id);
$this->db->from('posts AS p');
$this->db->join('posts_categories AS pc', 'pc.post_id = p.post_id', 'inner');
$this->db->join('categories AS c', 'pc.category_id = c.category_id', 'inner');
$q = $this->db->get();
Thanks for any help.