I have a 3 table tag system, topics, tags and tagtopic.
I now want to display the various tags for each topic as I display the topic. Since there are multiple tags for one topic, when I do the query below, I get multiple rows and the topic displays multiple times, once for each row. I don't think I can use a groupby as I'm not doing anything mathematical with the columns. What I really would like would be for each topic, display the topic and then a list of tags for a post such as (for Siri), 'iphone,smartphone,Siri'. tables:
topics
id | name |userid
tags
id | topicid | topicname
tagtopic
id | tagid | topicid '
$sql = "SELECT * FROM `topics` t
LEFT JOIN `tagtopic` tagtopic
on t.id = tagtopic.topicid
WHERE t.id= '12'";
Should mention that display is done with while($row = mysql_fetch_array($res)) so that it is displaying the rows of the recordset. I would like it to display the topic once, but since there are multiple rows created for the tags, it is displaying multiple times.
Do I have to give up on the join and do a subquery? Thanks for any suggestions.
tags.topicnameinstead be calledtags.tagname?