【发布时间】:2016-04-14 01:20:33
【问题描述】:
我有一个从数据库中获取项目的网站。目前的方式是所有项目都在一个列中。我希望这些项目出现在 3 列中,然后在它们下面再出现 3 列,依此类推。有人知道怎么做吗?
这是我的代码
<?php
// Default query for this page:
$q = "SELECT * FROM item";
// Create the table head:
echo '
<div class="container">
<div class="table-responsive">
<table border="5" class="col-lg-4" cellspacing="3" cellpadding="3" align="center">
<tr>
<td align="left" width="15%"><b>Photo</b></td>
<td align="left" width="5%"><b>Condition</b></td>
</tr>
</div>
</div>
</div>
</div>
';
// Display all the items, linked to URLs:
$r = mysqli_query ($dbc, $q);
while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) {
$directory = '/uploads';
$file= $row['image_name'];
// Display each record:
echo "
<tr>
<td align=\"center\"><image src=$directory/$file title='$row[image_name]' width='213' height='200'></td>
<td align=\"center\">{$row['state']}</td>
</tr>
";
}
echo '</tbody>';
echo '</table>';
mysqli_close($dbc);
【问题讨论】:
-
这与 PHP 没有任何关系,都是关于 HTML 和 CSS 的。例如,如果您将
table替换为一系列div元素,那么您可以使用 CSS 为这些divs 创建各种流畅的布局。 -
我将如何格式化它以便 div 放在我想要的位置?
-
您要制作一张桌子吗?另外,您获得的数据是什么样的?这个问题很模糊。