【问题标题】:Displaying info from database through while loop in a HTML table通过 HTML 表中的 while 循环显示来自数据库的信息
【发布时间】:2015-05-07 09:03:05
【问题描述】:

我正在尝试将我的广告放入表格中。我想在一行中显示三个最受欢迎的广告在主页上。然而,信息和照片根本没有正确显示,它们遍布整个页面。有人可以告诉我应该在哪里放置 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");?>

【问题讨论】:

  • 如果您有实时网址,您能否发布实时网址,以便我们查看输出:)
  • 啊抱歉@DavidAnderton它没有直播:((
  • 整页?可以加个截图吗?
  • 这很难理解,但我相信这与&lt;div id="ads"&gt;&lt;table&gt;while 循环内的事实有关,它应该在它之前,特别是因为你要关闭这些标签循环结束后。

标签: php css html mysqli


【解决方案1】:

解决了! 为了使图像彼此相邻显示,桌子必须浮动。我将桌子向左浮动,所有图像都对齐了。 感谢大家的贡献。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-27
    • 1970-01-01
    • 2016-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-17
    相关资源
    最近更新 更多