![]() |
Multiple Categories - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Multiple Categories (/showthread.php?tid=32771) |
Multiple Categories - El Forum - 08-04-2010 [eluser]georgerobbo[/eluser] Hello. I'm trying to display multiple categories assigned to a blog entry in CodeIgniter. I can do so with standard PHP but not CI. Database Structure table: Blog BlogID BlogSlug BlogTitle BlogContent BlogPostDate BlogAmmendDate BlogThumb BlogStatus table: Category CategoryID The Category table: BlogCategory BlogID CategoryID In my controller I am successfully passing the 10 most recent blog entries to the view. What I want to achieve is for each entry to query all the categories assigned to that blog and then display them. Controller: Home Code: <?php View: multiple Code: <div id="content"> Multiple Categories - El Forum - 08-04-2010 [eluser]danmontgomery[/eluser] Why not just do that in the query you're using to fetch the blog? You haven't posted the model so I can't speculate what your query looks like, but it should be something like: Code: $this->db->select('Blog.*, GROUP_CONCAT(DISTINCT Category.CategoryName SEPARATOR ", ") AS categories', FALSE) |