I am trying to fetch data from database in tabular format. I have taken count variable as a number of rows and 5 columns. When I execute this query all results are fetched in multiple row and single columns. Here is my code :
<?php
include("connect.php");
$all_product = mysqli_query($connect, "SELECT * FROM product WHERE user_id='$fetch_user_id'");
echo '<table style="background-color:white; margin-left:50px; margin-right:50px;">';
$count = mysqli_num_rows($all_product);
$count = ($count / 5) + 1;
for ($i = 0; $i < $count; $i++) {
echo "<tr[$i]>";
for ($m = 0; $m < 5; $m++) {
echo "<td[$m]>";
while ($all = mysqli_fetch_array($all_product)) {
echo '<img src="' . $all['image'] . '" width="150px" height="150px" />
<div class="search_details">
<figcaption>' . $all['name'] . '</figcaption>
<figcaption>by ' . $all['brand'] . '</figcaption><figcaption>₨' . $all['price'] . '</figcaption>
<figcaption>Save: ₨' . $local_price . ', (' . $all['discount'] . '%)</figcaption><figcaption>In stock:' . $all['stock'] . '</figcaption></div>';
}
echo "</td[$m]>";
}
echo "</tr[$i]>";
}
echo "</table>";
?>
Any help ? Where am I going wrong ? Thank you in advance