このコードがTOTALの最後の収益を表示するだけで収益を合計できないのはなぜですか?適切に合計する方法は?
<table border="1">
<tr>
<th>Date</th>
<th>Route</th>
<th>Destination</th>
<th>Van No.</th>
<th>Waybill No.</th>
<th>Charge Invoice</th>
<th>Revenue</th>
<th>Strip/Stuff</th>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_PK['delivery_details_date']; ?></td>
<td><?php echo $row_PK['delivery_details_route']; ?></td>
<td><?php echo $row_PK['delivery_details_destination']; ?></td>
<td><?php echo $row_PK['delivery_details_van_no']; ?></td>
<td><?php echo $row_PK['delivery_details_waybill_no']; ?></td>
<td><?php echo $row_PK['delivery_details_charge_invoice']; ?></td>
<td><?php echo $row_PK['delivery_details_revenue']; ?></td>
<td><?php echo $row_PK['delivery_details_strip_stuff']; ?></td>
<?php $revenue = $row_PK['delivery_details_revenue'];
$sum += $revenue;?>
</tr>
<?php } while ($row_PK = mysql_fetch_assoc($PK));?>
</table>
TOTAL: <?php echo $revenue; ?> <br/>
TOTALは、最後に記録された収益を表示するだけで、すべてを追加するわけではありません。なぜですか?