簡體   English   中英

通過HTML表中的while循環顯示數據庫中的信息

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

我正在嘗試將廣告放在桌子上。 我想在首頁上一次顯示三個最受歡迎的廣告。 但是,這些信息和照片根本無法正確顯示,並且遍布頁面。 有人可以告訴我我應該在while循環中放置結束標記的位置嗎? 這是整個代碼。

<?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");?>

解決了! 桌子必須浮起才能使圖像彼此相鄰顯示。 我將桌子向左浮動,所有圖像對齊。 感謝大家的貢獻。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM