如何在下面的foreach循环中更新$total
的值?这是因为我想同时为Branch Total
的Branch Column的每个rowpan之后添加新行,同时需要更新rowpan的$total
的值。
<tbody>
<?php
$count = 0;
$count2 = 0;
$count3 = 0;
$total = 0;
$total2 = 0;
foreach ($reNominalRoll as $key => $value) {
if ($row_area->ADMIN_ID == $value->AREA_ID) {
$gTotalBorn += $value->Borne;
$gTotalSanc += $value->sanction;
$total = rowspan_count_groupby($reNominalRoll, 'ship', $value->ShipName, $value->PostingName, $value->Branch);
$total2 = rowspan_count_groupby($reNominalRoll, 'unit', $value->ShipName, $value->PostingName, $value->Branch);
?>
<tr class="allrow">
<!--Ship Col-->
<?php
if ($count != 0)
$count--;
else {
echo "<td rowspan=" . ($total) . ">" . $value->ShipName . "</td>";
$count = $total - 1;
}
?>
<!--Posting Col-->
<?php
if ($count2 != 0) {
$count2--;
} else {
echo "<td rowspan=" . ($total2 + 1) . ">" . $value->PostingName . "</td>";
$count2 = $total2 - 1;
}
?>
<!--Branch Col-->
<?php
if ($count3 != 0)
$count3--;
else {
echo "<td rowspan=" . ($total2 + 1) . ">" . $value->Branch . "</td>";
$count3 = $total2 - 1;
}
?>
<td><?php echo $value->Rank ?></td>
<td><?php echo $value->Part ?></td>
<td><?php echo $value->sanction;
$bTotalSanc += $value->sanction; ?></td>
<td><?php echo $value->Borne;
$bTotalBorn += $value->Borne; ?></td>
<td><?php echo $value->TotalIn ?></td>
<td><?php echo $value->TotalOut ?></td>
</tr>
<!--Branch Total Row-->
<?php
if ($count3 == 0) {
$total += 1;
echo "<tr>";
echo "<td style='color:#000;font-weight: bold;'>Branch Total</td>";
echo "<td style='color:#000;font-weight: bold;'>" . $bTotalSanc . "</td>";
echo "<td style='color:#000;font-weight: bold;'>" . $bTotalBorn . "</td>";
echo "<td style='color:#000;font-weight: bold;'></td>";
echo "<td style='color:#000;font-weight: bold;'></td>";
echo "<td style='color:#000;font-weight: bold;'></td>";
echo "</tr>";
$bTotalSanc = 0;
$bTotalBorn = 0;
}
}
}
}
?>
<!--Grand Total Row-->
<tr>
<td style="text-align: center; font-weight: bold;" colspan="5">Grand Total</td>
<td style="text-align: center; font-weight: bold;"><?php echo $gTotalSanc; ?></td>
<td style="text-align: center; font-weight: bold;"><?php echo $gTotalBorn; ?></td>
<td></td>
<td></td>
</tr>
</tbody>
以下是屏幕截图 view image
请帮助我