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'>