<? foreach ($comments as $comment) : ?>
<div class="comments">
<div class="row comtext">
<div class="comname">
<?=$comment['name'];?>
<br>
<?=formatTime($comment['date']);?>
</div>
<div class="comtent">
<?=$comment['text'];?>
</div>
<div class="delete">
<button class="btn btn-sm btn-outline-light" id="<?=$comment['id']?>">Удалить</button>
</div>
</div>
</div>
<? endforeach;?>
$sqlComm = 'SELECT comments.id, comments.author_id, comments.date, comments.text,
comments.post_id, users.name FROM comments
JOIN posts ON posts.id = comments.post_id
JOIN users ON users.id = comments.author_id
WHERE posts.id = ' . $_GET['id'] .
' ORDER BY comments.date DESC';
$comments = $db->query($sqlComm);
//тут код который добавит комментарий, а далее
$sqlComm = 'SELECT comments.id, comments.author_id, comments.date, comments.text,
comments.post_id, users.name FROM comments
JOIN posts ON posts.id = comments.post_id
JOIN users ON users.id = comments.author_id
WHERE posts.id = ' . $_GET['id'] .
' ORDER BY comments.date DESC';
$comments = $db->query($sqlComm);
foreach ($comments as $comment) : ?>
<div class="comments">
<div class="row comtext">
<div class="comname">
<?=$comment['name'];?>
<br>
<?=formatTime($comment['date']);?>
</div>
<div class="comtent">
<?=$comment['text'];?>
</div>
<div class="delete">
<button class="btn btn-sm btn-outline-light" id="<?=$comment['id']?>">Удалить</button>
</div>
</div>
</div>
<? endforeach;?>
// кусок который аякс с отправкой коммента
.done(function (data) {
$('#comments_box').html(data); // здесь comments_box - ид врапера коментариев
})