我创建了一个脚本,它使用 php 动态填充表的字段。如果您查看下面的代码片段,现在我想添加所有$sub_total
内容以创建一个$total_cost
. 不确定我是否很好地解释了这一点,但任何方向都将不胜感激。
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// Calculate hours done per day
$hrs_done = $row['time_out'] - $row['time_in'];
if($hrs_done > $row['con_hr']){$hrs = $hrs_done;}
else{$hrs = $hrs_done;}
// echo out results into a table
echo "<tr>";
echo '<td bgcolor="#FFFFFF">' . $row['date'] . '</td>';
echo '<td bgcolor="#FFFFFF">' . $hrs . '</td>';
echo '<td bgcolor="#FFFFFF">' . $row['rate'] . '</td>';
echo '<td bgcolor="#FFFFFF">'?>
// Multiply hrs by rate to get sub total charge for day
<?php $sub_total = $hrs * $row['rate'];
echo $sub_total ;
?>
<?php '</td>';
echo "</tr>";
}
// close table>
echo "</table>";