I have a code that have an access to my database's "comments" table. I did a connection variable and created all the stuff in order to get table. But I when save and refresh the page, it is showing this error below. What's the problem?
<?php
// connection
$connection = mysqli_connect(
$config['db']['server'],
$config['db']['username'],
$config['db']['password'],
$config['db']['name']
);
if ($connection == false)
{
echo 'Error!<br>';
echo mysqli_connect_error();
exit();
}
// comments
$сomments = mysqli_query($connection, "SELECT * FROM `comments` ORDER BY `articles_id` DESC LIMIT 5");
while ($com = mysqli_fetch_assoc($comments))
{
?>
<article class="article">
<div class="article__image" style="background-image: url(https://www.gravatar.com/avatar/<?php echo md5($com['email']); ?>?s=125);"></div>
<div class="article__info">
<a href="/article.php?id=<?php echo $com['articles_id']; ?>"><?php echo $com['author']; ?></a>
<div class="article__info__preview"><?php echo mb_substr(strip_tags($com['text']), 0, 100, 'utf-8') . ' ...'; ?></div>
</div>
</article>
<?php
}
?>
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in W:\domains\itblog.kg\includes\sidebar.php on line 56 . What is the problem?