Hello,
I am looking for a solution how to implement comments of comments system. Something like Facebook wall where users can post comments and comment already posted comments.
So, the query while loading posted comments have to check for subcomments for each comment.
This is an unoptimized way of doing this:
$result1 = mysql_query("SELECT id,comment FROM comments
WHERE user='$uid' order by id DESC limit $start,$step")or die('Error');
while(list($commentid, $comment) = mysql_fetch_row($result1)) {
echo "$comment<br />";
$result2 = mysql_query("SELECT comment FROM comments
WHERE parent_id='$commentid' order by id DESC")or die('Error');
while(list($subcomment) = mysql_fetch_row($result2)) {
echo " $subcomment<br />";
}
}
But it's not a good idea. If there are 20 comments on a page, the script will make 20 additional queries to get all subcomments. So, I need another way.
Thanks.