How to get the sum from the loop? (php)
Can anybody help me to get the sum or total of the $total_h in the below
loop? I just need to display the sum of $total_h after the loop has
finished so I'll know how many hours I've worked.
<?php
$get_time = mysql_query("select * from tbl_timekeep where emp_id =
'OJT0125' order by date desc");
while ($fect_time = mysql_fetch_array($get_time))
{
if ($fect_time[3] == '----' || $fect_time[3] == 'No Out')
{
$out = '17:00:00';
}
else
{
$out = $fect_time[3];
}
$from = new DateTime($fect_time[2]);
$to = new DateTime($out);
$total_h = $from->diff($to)->format('%h.%i');``
echo $fect_time[2].'to'.$fect_time[3]." = [ $total_h ]<br>";
}
?>
No comments:
Post a Comment