php - Combining Data from two MySQL tables -


i'm trying combine data 2 tables in mysql php.

i want select data (id, title, post_by, content , created_at) "posts" table.

then select comment_id count "comments" table if comment_id equals posts id.

finally, echo/print on order:

<? echo $row->title; ?> posted <? echo $row->post_by; ?> on <? echo $row->created_at; ?> cst <? echo $row->content; ?> <? echo $row->comment_id; ?> comments | <a href="comment.php?id=<? echo $row->id; ?>">view/post comments</a> 

i'm uncertain how "combine" data 2 tables. have tried numerous things , have spent several evenings , have had no luck.

any appreciated!

select p.id, p.title, p.post_by, p.content, p.created_at, count(c.comment_id) posts p left join comments c on p.post_id = c.comment_id group p.id, p.title, p.post_by, p.content, p.created_at 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -