Hello i'm trying to get the comments form the releative table 'comments' of my database. I want to display if there are no comments a message like : 'no results', else if there are comments to display the comment box withe username the date and the message of the comments i have tryied this but with no result's :
function getComments($conn) {
$sql = ("SELECT * FROM comments ORDER BY cid DESC LIMIT 5");
$result = $conn->query($sql);
foreach($row as $result) {
if(!mysql_num_rows($sql))
{
echo 'No results';
}
else
{
echo "<div class='comment-box2'><p>";
echo $row['users']."<br>";
echo $row['date']."<br>";
echo nl2br($row['message']);
echo "</p>
</div>";
}
}
}