I am stuck into a very annoying problem. I have simple Post and Comments section on my website just like a blog i-e, two tables "posts" and "comments":
posts -> idpost, title, text, date comment -> idcomment, idpost_cmt, email, message, idcomment_cmt
Very simple. idpost_cmt -> Foreign Key to posts table
The last field in comment table i-e, "idcomment_cmt" will be used if someone sends comment on an already existing comment:
Post
|_ Comment 1
|_ Comment 2
|_ Comment 3
|_ Comment 4
__|_ Comment 4.1
__|_ Comment 4.2
|_ Comment 5 . . . so on ...
Now what I exactly want is to query all posts and comments in single mysql query. What I am doing now is that first I get all posts and then loop through each post. In each cycle, I query comments using the current post ID. And then loop through comments and on each comment cycle, query sub-comments using current CommentID.
As you can see that this way, a single page request might need 500 or more sql queries which is too much for database server. If anyone could help me how to accomplish this, I would really really appreciate.
Thanks a lot...