【问题标题】:How to do make html foreach table?如何制作html foreach表?
【发布时间】:2018-03-20 14:12:02
【问题描述】:

我试过这样做,但最大的问题是 foreach 在这里我有照片: Problem

Here is my table picture

这是代码,但仍有问题:

    <div class="row">
        <table class="table table-bordered table-striped table-highlight">
            <tbody>
            <tr height="100">
                <td rowspan="6"  height="120" width="3%" style="vertical-align: middle;">
                    <p style="white-space: nowrap;writing-mode: vertical-lr;transform: rotate(180deg);font-weight: bold;"><font >Here is my title </font></p>
                </td>
                <td   colspan="3">
                <font>Name</font>
                </td>
                <td   width="64">
                <font>Article</font>
                </td>
                <td  width="64">
                <font>Price</font>
                </td>
                <td   width="64">
                <font>Date</font>
                </td>
            </tr>
            <tr height="20">
                <td colspan="3" rowspan="5" height="120" ></td>
                <td rowspan="5" style="vertical-align: top;"></td>
                <td rowspan="5" style="vertical-align: top;"></td>
                <td rowspan="5" style="vertical-align: top;"></td>
            </tr>
            <tr height="15">
            </tr>
            <tr height="15">
            </tr>
            <tr height="15">
            </tr>
            <tr height="15">
            </tr>
            </tbody>
        </table>
    </div>

我该怎么做才能在我使用 foreach 时插入新的 td 和垂直 Here is my title 会在那里?

【问题讨论】:

  • 服务器端(哪种语言)?还是客户端?您要使用foreach 插入的数据在哪里?
  • @Taki 对不起,我忘记了。是 php 和数据来自数据库到这个表中。
  • 只是想说表头有一个标签&lt;th&gt;。放在&lt;tbody&gt;之前

标签: php html css html-table


【解决方案1】:

好的,所以你使用php 这是一个非常基本的示例,说明如何做到这一点,我假设你已经做了query 和获取部分,这是对你的数据结构的猜测,您可以根据自己的喜好调整它:

<div class="row">
    <table class="table table-bordered table-striped table-highlight">
        <tbody>
        <tr height="100">
            <td rowspan="100%"  height="120" width="3%" style="vertical-align: middle;">
                <p style="white-space: nowrap;writing-mode: vertical-lr;transform: rotate(180deg);font-weight: bold;"><font >Here is my title </font></p>
            </td>
            <td   colspan="3">
            <font>Name</font>
            </td>
            <td   width="64">
            <font>Article</font>
            </td>
            <td  width="64">
            <font>Price</font>
            </td>
            <td   width="64">
            <font>Date</font>
            </td>
        </tr>
        <?php
            foreach($data as $key => $value){
                echo '<tr height="20">';
                    echo '<td colspan="3">'.$value['name'].'</td>';
                    echo '<td width="64" style="vertical-align: top;">'.$value['article'].'</td>';
                    echo '<td width="64" style="vertical-align: top;">'.$value['price'].'</td>';
                    echo '<td width="64" style="vertical-align: top;">'.$value['date'].'</td>';
                echo '</tr>';
            }
        ?>
        </tbody>
    </table>
</div>

这是一个小提琴:https://jsfiddle.net/kkpjx328/

我希望这会有所帮助。

PS :关于您的下一个问题,请考虑添加数据结构,如果可能,请添加您迄今为止尝试过的示例或代码示例,以便我们提供更具体的答案

【讨论】:

猜你喜欢
  • 2018-01-01
  • 2018-12-16
  • 1970-01-01
  • 1970-01-01
  • 2013-10-01
  • 2021-11-23
  • 2014-11-17
  • 1970-01-01
  • 2019-12-29
相关资源
最近更新 更多