From 487ad1e3762f11e0ab866fac3a5bdd17d45271b4 Mon Sep 17 00:00:00 2001 From: biglyderv Date: Thu, 12 Dec 2024 00:08:19 -0500 Subject: [PATCH] fix nested replies --- libs/comment.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/libs/comment.php b/libs/comment.php index 2d5a70e..96d0a2f 100644 --- a/libs/comment.php +++ b/libs/comment.php @@ -37,11 +37,20 @@ prepare("SELECT * FROM comment WHERE id = ? ORDER BY date DESC"); - $stmt->execute([ - $idr - ]); - $posts1 = $stmt->fetchAll(PDO::FETCH_DEFAULT); + $posts = array(); + + $theId = $idr; + + while (true) { + $stmt = $db->prepare("SELECT * FROM comment WHERE id = ? ORDER BY date DESC"); + $stmt->execute([ + $theId + ]); + $posts1 = $stmt->fetchAll(PDO::FETCH_DEFAULT); + if (is_null($posts1) || count($posts1) < 1) break; + $theId = $posts1[0]['targetid']; + $posts = array_merge($posts1,$posts); + } $stmt = $db->prepare("SELECT * FROM comment WHERE targetType = ? AND targetId = ? ORDER BY date DESC LIMIT ? OFFSET ?"); $stmt->execute([ @@ -53,9 +62,13 @@ $posts2 = $stmt->fetchAll(PDO::FETCH_DEFAULT); - $posts = array_merge($posts1,$posts2); + $edge = count($posts); + $posts = array_merge($posts,$posts2); - foreach ($posts as $post) { ?> + foreach ($posts as $key => $post) { + if ($key == $edge) { ?> +

Replies

+
.png' class='avatar-img'>