用 SQL 数据和 PHP 填充 HTML 表


Populate HTML table with SQL data and PHP

我正在尝试使用几个循环填充一个表。

第一个循环用一行用户填充表标题,这没有问题。

问题是将 tds 填充为具有正确票号的行。

我可以在单个 td 中获取订单列中的所有数字,这不是它应该的工作方式

像这样的东西,

---------------------
user1 | user2 | user3
---------------------
00001 | 00004 | 00007
00002 | 00005 | 00008
00003 | 00006 | 00009
---------------------

它应该是,

---------------------
user1 | user2 | user3
---------------------
00001 | 00004 | 00007
---------------------
00002 | 00005 | 00008
---------------------
00003 | 00006 | 00009
---------------------

你明白了。

这是我为此使用的代码,

<table class="table table-hover">
    <thead>
        <tr>
            <th scope="row">
                <?php
                $userName = functionName();
                for ($userName->rewind(); $userName->pointer < $userName->size; $userName->next()) {
                    $record = $userName->current();
                    $firstName = $record->fields->FirstName;
                    ?>
                <th><?php echo $firstName; ?></th>
<?php } ?>
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <th scope="row">
                <?php
                for ($userName->rewind(); $userName->pointer < $userName->size; $userName->next()) {
                    $record = $userName->current();
                    $firstName = $record->fields->FirstName;
                    ?>
                <td>
                    <?php
                    $userCase = functionCase($firstName);
                    for ($userCase->rewind(); $userCase->pointer < $userCase->size; $userCase->next()) {
                        $record = $userCase->current();
                        $caseNumber = $record->fields->CaseNumber;
                        $status = $record->fields->Status;
                        echo $caseNumber;
                        ?>
                    <?php }
                ?>
                </td>
<?php } ?>
            </th>
        </tr>   
    </tbody>
</table>

我想我可能为该部分使用了错误的逻辑和循环。

任何想法如何获得正确的表格结果?

我认为您使用的HTML表格布局不正确。

你在 th 里面有一个 td,据我所知这是不允许的。如果要在多行中显示数据,则必须为每一行创建一个 tr。然后,trs 可以包含 th 和 td 项。有关有效的表格布局,请参阅 http://www.w3schools.com/tags/att_th_scope.asp

相关文章: