I am trying to make simple mysql select query, I have 3 tables
post: post_id...
tags: tag_id, tag_name
post_tag: id_post, id_tag
and I wrote this query:
$sql=mysql_query("select * from post
LEFT JOIN post_tag
ON post_tag.id_post = post.post_id
LEFT JOIN tags
ON post_tag.id_tag = tags.tag_id
GROUP BY post_id
ORDER BY post_id
DESC LIMIT 5");
but I am getting only one tag per post even there is more tags with same post_id?
while($row=mysql_fetch_array($sql))
{
$post_id =$row['post_id '];
$tag_name=$row['tag_name'];
echo $post_id $tag_name;
}
You could use something like:
This will give you one record for each post with a comma seperated list of every tagname that is linked to that post.