I'm trying to fit my adverts into a table. I want to display three of the most popular ads on the home page, in one line. However the information and the photos are not displaying properly at all and they are all over the page. Could someone tell me where I should be placing the closing tag for the while loop? Here is the whole code.
<?php include("header.php");?>
<!-- Left SIDEBAR -->
<?php include("sidebar.php");?>
<!-- Right CONTENT -->
<div id="right_content">
<h1>Our most popular ads...</h1>
<?php include("functions/connect.php");
$sql = "SELECT * FROM horses ORDER BY likes DESC LIMIT 3";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "";
// output data of each row
while($row = $result->fetch_assoc()) {
$hid=$row['HorseID'];
// Get image
$sqlimg= "SELECT * FROM images where Horse_ID='$hid'";
$resultimg = $conn->query($sqlimg);
$rowimg = $resultimg->fetch_assoc() ;
?>
<div id="ads">
<table>
<tr>
<td><img src="uploads/horse1.jpg"></td>
</tr>
<tr>
<td>
<?php echo $row['HorseName']; ?>
</td>
</tr>
<?php }
} else {
?>
<br />
<div id="alert">There are no horses to display at the moment.</div>
<?php
}
$conn->close();
?>
</table>
</div>
</div>
<?php include("footer.php");?>
Solved! The table had to be floated in order for the images to display next to each other. I floated the table to the left and all the images aligned. Thanks everyone for your contributions.