Combining Data from two MySQL tables.
Posted
by Nick
on Stack Overflow
See other posts from Stack Overflow
or by Nick
Published on 2010-04-30T19:40:55Z
Indexed on
2010/04/30
19:47 UTC
Read the original article
Hit count: 241
I'm trying to combine data from two tables in MySQL with PHP.
I want to select all the data (id, title, post_by, content and created_at) from the "posts" table.
Then I would like to select the comment_id COUNT from the "comments" table IF the comment_id equals the posts id.
Finally, I would like to echo/print something on this order:
<? echo $row->title; ?>
Posted by <? 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 as to how to "combine" the data from two tables. I have tried numerous things and have spent several evenings and have had no luck.
Any help would be greatly appreciated!
© Stack Overflow or respective owner