I'm trying to show all information from my mysql database using while loop, of course I could do this without while loop, but I want to show this information organized in html divs.
$cnt = mysqli_num_rows(mysqli_query($CONNECT, "SELECT * FROM `reviews`"));
echo $cnt;
while ($Row = mysqli_fetch_assoc($cnt)) {
echo '<div class="panel panel-default">
'.$Row['name'], $Row['text'].'
</div>';
}
Whats bad in my code, how I can fix it to make it work?
You need to fetch the associative array on the query, not the count.
$q = mysqli_query($CONNECT, "SELECT * FROM `reviews`");
$cnt = mysqli_num_rows($q);
echo $cnt;
while ($Row = mysqli_fetch_assoc($q))
{
echo '<div class="panel panel-default">
'.$Row['name'], $Row['text'].'
</div>';
}
You need a valid resource from mysql and you get that from mysqli_query
with mysql_num_rows
you get the number of rows in your table but no resource.
$res = mysqli_query($CONNECT, "SELECT * FROM `reviews`");
while ($Row = mysqli_fetch_assoc($res)) {
echo '<div class="panel panel-default">
'.$Row['name'], $Row['text'].'
</div>';
}
So if you rewmore the mysqli_num_rows
command it should work if your connection is correct.