![]() |
MySQL Problem - Help (Unresolved) - 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: MySQL Problem - Help (Unresolved) (/showthread.php?tid=23782) |
MySQL Problem - Help (Unresolved) - El Forum - 10-21-2009 [eluser]georgerobbo[/eluser] Hello, I am trying to connect blog posts with their related tags. My database structure is as follows. table: tag ID Int // This is the Primary Key post Int // This is the ID of each blog post tag Varchar // This is the tag table: post ID Int // Primary Key Title Varchar Author Varchar Timestamp Varchar Filename Varchar Description Varchar Category Varchar Comments Varchar Favourites Varchar Views Varchar My problem is that when I join the tables, only the first tag for each post is selected, rather than all of them. My model, controller and view are: Code: function the_post($permalink) Code: function single() Code: <div id="page"> MySQL Problem - Help (Unresolved) - El Forum - 10-21-2009 [eluser]markup2go[/eluser] Take a look at the MySQL GROUP_CONCAT() function, I believe that is what you're looking for. MySQL Problem - Help (Unresolved) - El Forum - 10-21-2009 [eluser]georgerobbo[/eluser] Thanks. I'm afraid I don't quite understand how to use it with my join and select statement? MySQL Problem - Help (Unresolved) - El Forum - 10-21-2009 [eluser]markup2go[/eluser] You would use it in your select. Here's an example of how I did it with a similar database setup: Code: $this->db->select("classes.*, GROUP_CONCAT(DISTINCT DATE_FORMAT(class_dates.date, '%m/%d/%Y') ORDER BY date ASC SEPARATOR ',') as dates", FALSE); So you would do something like Code: $this->db->select("post.*, GROUP_CONCAT(DISTINCT tag.tag ORDER BY tag ASC SEPARATOR ',') as tag", FALSE); |