如何删除 table 头部 <th> 间隙

How to remove table head <th> gap

我有6个table头和6个table数据,但是从图中可以看到table头有一个空隙,但是如何消除空隙? 有6个table头,但我需要7个table数据才能使它相等......

如图所示:

为了更清晰,我将所有 td 和 th 背景设置为黑色(第 6 和 6 td):

编码:

<table class="table table-bordered" style='padding: 20px 20px;display:table-header-group;table-layout: fixed;'>
        <tr>
            <th>Date</th>
            <th>Time</th>
            <th>Product<th>
            <th>Quantity</th>
            <th>Price</th>
            <th>Payment Method</th>
        </tr>

        <?php

        while($row=mysqli_fetch_array($res)){                    
            echo "<tr>";
            echo "<td>"; echo $row['orderdate']; echo "</td>";
            echo "<td>"; echo $row['ordertime']; echo "</td>";
            /////////////////productname
            echo "<td>";
            echo "<table>";           

            while($row2=mysqli_fetch_array($res2)){

            echo "<tr>";
            echo "<th>"; echo $row2['listingname']; echo "</th>";
            echo "</tr>";
            }

            echo "</table>";
            echo "</td>"; 
            echo "<td>"; echo "qty"; echo "</td>";
            echo "<td>"; echo "price"; echo "</td>";
            echo "</tr>";

            }
        ?>
    </table>

在您的代码中,您声明了 6 列,但只感觉到其中的 3 列。

因此,为了使其正确,您应该在最后一个 td 中添加一个 colspan,如下面的代码:

<table class="table table-bordered" style='padding: 20px 20px;display:table-header-group;table-layout: fixed;'>
    <tr>
        <th>Date</th>
        <th>Time</th>
        <th>Product<th>
        <th>Quantity</th>
        <th>Price</th>
        <th>Payment Method</th>
    </tr>
    <?php

        while($row=mysqli_fetch_array($res)){                    
            echo "<tr>";
            echo "<td>"; echo $row['orderdate']; echo "</td>";
            echo "<td>"; echo $row['ordertime']; echo "</td>";
            /////////////////productname
            echo "<td colspan='4'>";
            echo "<table>";           

            while($row2=mysqli_fetch_array($res2)){

                echo "<tr>";
                echo "<th>"; echo $row2['listingname']; echo "</th>";
                echo "</tr>";
            }

            echo "</table>";
            echo "</td>"; 

            echo "</tr>";

        }
    ?>
</table>

所以实际上我在产品结束时错过了一个/th,感谢所有帮助的人

 <tr>
                        <th>Date</th>
                        <th>Time</th>
                        <th>Product</th>
                        <th>Quantity</th>
                        <th>Price</th>
                        <th>Payment Method</th>
                    </tr>