i have three tables, 1.comment, 2.nested comment, 3. username i'm currently struggling how to output the nested comment the best way
$sql = "SELECT comment.*, nested_comment.subject AS nc_subject, users.username
FROM comment
INNER JOIN users
ON comment.user_id = users.id AND comment.blog_id = $id
LEFT JOIN nested_comment
ON comment.id = nested_comment.comment_id
ORDER BY comment.id DESC";
my current view-code
<? while($comment = $result->fetch_object()) { ?>
<p> <?=$comment->subject . ' by ' . $comment->username; ?> </p>
<hr>
<div class="nested_comment">
<p> <?=$comment->nc_subject; ?> </p>
</div>
all data i wanted is shown, but say i have -2 nested comment- in -1 parent comment-, the parent comment still showing up 2 times insted only once.
I can check with if-else statement on the while-loop, if the previous comment id is the same, but i'm looking for more elegant/efficent solution for this, I'm not sure how to 'group' it on sql