【发布时间】:2017-11-16 19:52:58
【问题描述】:
我有一个表,其记录由数据库的结果填充,并且使用了 foreach 循环。 我希望将具有单个单元格值的几列与其他列合并。 喜欢:
Leave Type | Max Days | Leave Taken | Leave Balance | Roll Over
Float | 3 | 2 | 1 |
Personal | 3 | 2 | 1 | 5
Sick | 3 | 2 | 1 |
Mourning | 3 | 2 | 1 |
前四条记录是用foreach循环填充的,我需要单独计算第五列并追加。
这是我的 HTML:
<table class="table table-striped table-hover" id="leave_balance_table">
<thead>
<tr>
<th>Leave Type</th>
<th>Max Days</th>
<th>Leave Taken</th>
<th>Leave Balance</th>
<th>Roll Over</th>
</tr>
</thead>
<tbody>
<?php
$totalLeaveTaken = 0.00;
$totalBalance = 0.00;
$totalRows = count($GetEmployeeLeaveBalance);
foreach ($GetEmployeeLeaveBalance as $member):
$totalLeaveTaken += $member['usedDays'];
$totalBalance += $member['Remaining_Leave_Days'];
$leaveBalance = floatval($member['Remaining_Leave_Days']);
?>
<tr>
<td><?php echo $member['title']; ?></td>
<td><?php echo $member['maxDays']; ?></td>
<td><?php echo $member['usedDays']; ?></td>
<!-- <td><?php echo gettype($leaveBalance);?></td> -->
<td
<?=
($leaveBalance < 0) ?
"style='background-color:red;font-weight:bold;color:white;'" : ""
?>
>
<?php echo $member['Remaining_Leave_Days']; ?>
</td>
<!-- <td rowspan="<?= $totalRows; ?>">Some computed value</td> -->
</tr>
<?php endforeach; ?>
<tr>
<td></td>
<td></td>
<td style="background-color: #33CCFF; font-weight: bold;">Total: <?php echo number_format($totalLeaveTaken, 2); ?></td>
<td style="background-color: #33CCFF; font-weight: bold;">Total: <?php echo
number_format($totalBalance, 2); ?></td>
</tr>
</tbody>
</table>
如何从 foreach 循环中取出第五列并附加它?
【问题讨论】:
标签: php html foreach html-table