I am populating a table from a database. The data is being retrieved correctly however it is not being displayed correctly. This is how I want it to be displayed:
+----------------------------------------------------+
| vehicle 1 | vehicle 2 | vehicle 3 | vehicle 4 |
|-----------------------------------------------------|
| vehicle 5 | vehicle 6 | vehicle 7 | vehicle 8 |
|-----------------------------------------------------|
| vehicle 9 | veh 10 | veh 11 | veh 12 |
+----------------------------------------------------+
This is what I am getting:
+----------------------------------------------------+
| vehicle 1 | vehicle 1 | vehicle 1 | vehicle 1 |
|-----------------------------------------------------|
| vehicle 2 | vehicle 2 | vehicle 2 | vehicle 2 |
|-----------------------------------------------------|
| vehicle 3 | vehicle 3 | vehicle 3 | vehicle 3 |
+----------------------------------------------------+
Here is my code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$conn=mysqli_connect("localhost","root","","ezwayautos");
if($conn)
{
$sql="SELECT * FROM vehicles ORDER BY RAND() LIMIT 12";
$result=mysqli_query($conn,$sql);
}
if(! $result )
{
die('Could not get data: ' . mysqli_error($conn));
}
$rows = 3;
$cols = 4;
echo "<table>";
while($row = mysqli_fetch_assoc($result))
{
for($tr=1;$tr<=$rows;$tr++)
{
echo "<tr>";
for($td=1;$td<=$cols;$td++)
{
echo "<td height='160' valign='top' class='featured'>";
echo "<div class='Image-Thumbnail'>";
echo "<a href=''>";
echo "<img src='".$row['image']."' width='160' height='54' alt='".$row['vehicle_name']."'>";
echo "</a>";
echo "</div> <a href=''>" .$row['vehicle_name']. "</a>";
echo "</td>";
}
echo "</tr>";
}
}
echo "</table>";
?>
Please help