简体   繁体   English

通过HTML表中的while循环显示数据库中的信息

[英]Displaying info from database through while loop in a HTML table

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? 有人可以告诉我我应该在while循环中放置结束标记的位置吗? 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. 感谢大家的贡献。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM