I have two tables post
and comment
. table 1
post having following columns
id title description
table 2
comment having following columns
id comment_id
id
each post can have several comments. I want to fetch single post and all its related comment for every $id
.
I tried this one
$sql = "select * from post join comment on post.id= comment.id where post.id=$id";
hence $id=argument result post 1 having comment 1,post 1 having comment 2 so i want that post 1 should not be repeated.
If you want data from the posts table and the comments table, you have to either do two queries or just ignore the duplicate posts when looping through the results. There is no way to keep the posts data from being duplicated for each comment.