我有6个表头和6个表数据,但是从图像中可以看到有一个表头间隙,但是如何消除该间隙? 有6个表头,但我需要7个表数据才能使其相等……
如下图所示:
为了更加清楚,我将所有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>
答案 0 :(得分:0)
因此,实际上我错过了产品末位的1分之一,谢谢大家的帮助
<tr>
<th>Date</th>
<th>Time</th>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
<th>Payment Method</th>
</tr>
答案 1 :(得分:-1)
在您的代码中,您声明6列,但只感觉其中3列。
因此,为了正确处理,您应该在最后一个colspan
上添加一个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 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>