"But it did not work as I expected."
... but you do not say what you expected.
Assuming the implied schema in your request is correct, then you donβt just need to show the messages once:
$lastpostid=false; while ($r=mysql_fetch_assoc($result)) { if ($r['post_id']!=$lastpost) { print "Post: " . $r['title'] . "<br />\n"; $comment_id=1; $lastpost=$r['post_id']; } print "Comment # $comment_id : " . $r['comment_body'] . "<br />\n"; $comment_id++; }
But, as I said, this means that your request is correct (i.e. these comments are not hierarchical). A.
WITH.
source share