簡體   English   中英

用 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

暫無
暫無

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

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