I want to display comments on multiple pages, so I want to select the comments from the database on 1 page and include those comment on all the other pages.
I can select and display each comment, but some post's don't have comments. Now I get this error for each post without comments. Notice: Undefined variable: showComments in ...\comments.php on line 7
The page to select the comments:
class Comment {
          public static function displayComments($postId) {
                  $comments = DB::query('SELECT comments FROM table WHERE post_id=:postid', array(':postid'=>$postId);
                  foreach($comments as $comment) {
                          $showComments[] = $comment['comment'];
                  }
                          return $showComments;//this is line 7
          }
}
Other pages:
$postOutput = "postImg, postLikes, postLikeButton";
if(Comment::displayComments($post['id']) >= 1) {
           $comments = Comment::displayComments($post['id']);
           foreach ($comments as $comment) {
                   $postOutput .= $comment;
           }
}
$postOutput .= "postCommentForm";
echo $postOutput;
