I have a comments table that looks like this: the contents of the layout are also added:
+------------+---------+----------+-------------------+------------------------------------+---------------------------+ | comment_id | user_id | movie_id | comment_parent_id | comment_content | comment_creation_datetime | +------------+---------+----------+-------------------+------------------------------------+---------------------------+ | 26 | 1 | 16329 | 0 | Första | 2016-01-24 10:42:49 | | 27 | 1 | 16329 | 26 | Svar till första | 2016-01-24 10:42:55 | | 28 | 1 | 16329 | 26 | Andra svar till förta | 2016-01-24 10:43:06 | | 29 | 1 | 16329 | 28 | Svar till "andra svar till första" | 2016-01-24 10:43:23 | +------------+---------+----------+-------------------+------------------------------------+---------------------------+
Im trying to display Reddit style comments like this image:

Im trying to get all comments SELECT * FROM comments WHERE movie_id = :movie_id ORDER BY comment_creation_datetime DESC and then recursively log them out.
I tried a bunch of foreach loops but nobody works as expected
foreach($this->comments as $value){ ?> <div class="comment"> Comment content <?php echo $value->comment_content; ?> <?php if($value->comment_parent_id > 0){ foreach($value as $sub_comment){ ?> <div class="comment"> comment comment on comment: <?php echo $value->comment_content; ?> </div> <?php }} ?> </div> <?php }
My question is:
How to undo comments in a nested Reddit style using a foreach loop?
source share