(sorry for my bad English)
I'm creating a website where users can post something and other users can leave a comment on that post.
I learned from a video from HowCode (youtube) that if you want to display the comments on multiple pages, it is usefull to create 1 page that selects the comments and on all the other pages I can 'include' those comments.
The problem is that it now only displays one comment while I have multiple comments on some posts.
Does anyone know how to solve this?
On the page where I select the comments:
class Comment {
public static function displayComments($postId) {
$comments = DB::query('SELECT * FROM table WHERE post_id = $postId');
foreach($comments as $comment) {
$commentDisplay = $comment['comment'].' ~ by a user';
return $commentDisplay;
}
}
}
On the page where I display the comments:
$showComments = Comment::displayComments($_GET['postid']);
echo $showComments;