如何将数据库中的项放入格式良好的表中


how to get items from database into a well formatted table

我有一个从数据库中获取项目的网站。目前的情况是,所有项目都在一列中。我想把这些项目分成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);

如果我做对了,每行需要3个项目,并且您使用的是twitter引导css框架。

您的问题主要来自于您正在使用的HTML结构。

试试这样的东西:

<div class="container">
    <div class="row">
        <div class="col-lg-4">item 1</div>
        <div class="col-lg-4">item 2</div>
        <div class="col-lg-4">item 3</div>
        <div class="col-lg-4">item 4</div>
        <div class="col-lg-4">item 5</div>
        <div class="col-lg-4">item 6</div>
    </div>
</div>

看起来HTML被中止了,这可能是显示问题的原因。

试着从标记的线上方删除这4个结束div

//显示链接到URL的所有项目: