我想制作colspan auto。实际上,我已经创建了一个动态表,但有时候td会变空,所以我想扩展我的列宽,但我对此并不了解。是否可以使用自动colspan或任何其他方法来执行此操作?
您可以在下面看到我的表格:
<table>
<tr>
<td>General or OBC</td>
<td>125</td>
</tr>
<tr>
<td>SC or ST</td>
<td>65</td>
</tr>
<tr>
<td>PH Candidates</td>
<td>25</td>
</tr>
<tr>
<td>Pay the Exam Fee Through SBI Mops Debit Card, Credit Card, Net Banking or SBI E Challan Mode Only</td>
<td></td>
</tr>
</table>
这里也是我的PHP代码,
<table class="feedetails" id="feedetails">
<tr class="tblhead">
<th class="inricon" colspan="2">APPLICATION FEE</th>
</tr>
<?php
$stmt = $pdo->prepare("SELECT * FROM appfee where joblink=? and status='y' order by id asc");
if ($stmt->execute(array($joblink))) {
$rows = $stmt->rowCount();
if ($rows == "") {
echo '<style type="text/css">.feedetails{display: none;}</style>';
}else{
while ($row = $stmt->fetch()) {
echo'<tr>
<td>'.$row['category'].'</td>
<td>'.$row['fee'].'</td>
</tr>';
}
}
}
?>
</table>
答案 0 :(得分:1)
将while
循环更改为:
while ($row = $stmt->fetch()) {
if($row['fee'] !== '') { // if $row['fee'] is not empty then echo two TDs
echo '<tr>
<td>'.$row['category'].'</td>
<td>'.$row['fee'].'</td>
</tr>';
}
else { // otherwise, echo one TD with colspan == 2
echo '<tr><td colspan="2">'.$row['category'].'</td></tr>';
}
}