fix nested replies

This commit is contained in:
biglyderv 2024-12-12 00:08:19 -05:00
parent 22756c834e
commit 487ad1e376

View file

@ -37,11 +37,20 @@
</div> </div>
<?php <?php
$stmt = $db->prepare("SELECT * FROM comment WHERE id = ? ORDER BY date DESC"); $posts = array();
$stmt->execute([
$idr $theId = $idr;
]);
$posts1 = $stmt->fetchAll(PDO::FETCH_DEFAULT); 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 = $db->prepare("SELECT * FROM comment WHERE targetType = ? AND targetId = ? ORDER BY date DESC LIMIT ? OFFSET ?");
$stmt->execute([ $stmt->execute([
@ -53,9 +62,13 @@
$posts2 = $stmt->fetchAll(PDO::FETCH_DEFAULT); $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) { ?>
<h2>Replies</h2>
<?php } ?>
<div class='comment'> <div class='comment'>
<div class='avatar'> <div class='avatar'>
<img src='/pfp/<?php echo $post['username'] ?>.png' class='avatar-img'> <img src='/pfp/<?php echo $post['username'] ?>.png' class='avatar-img'>