I have a database where I track time worked. The database has date, t_in & t_out and I return that in a web table. In the table I calculate the total time worked:
<td><?php $t_total = strtotime($row['t_out']) - strtotime($row['t_in']) ; echo gmdate('H:i', $t_total);?></td>
In the table footer I’d like to show the total time worked for the current month and the total time worked year to date.
<tr><td colspan='6'><span>Total time worked in <?php echo date('F')?>: <?php echo gmdate('H:i', $timeMonth);?></span></td></td>
<tr><td colspan='6'><span>Total time worked Year to Date: <?php echo gmdate('H:i', $timeYear);?></span></td></td>
I just don’t know how or where to do the calculation so I can call it in the table footer. I assume it needs to be done in the table, but nothing I’ve tried returns any results…
Here is the complete code:
<?php
$id = $_GET['id'];
$sql = "SELECT * FROM timetrack WHERE vol_id = '$id' ORDER BY date, t_in";
$result = mysql_query($sql) or die(mysql_error());
?>
<h4 style="margin-left:25px;">Dates and Times Worked</h4>
<table >
<thead>
<tr>
<th></th>
<th>Date</th>
<th>Department</th>
<th>Time In</th>
<th>Time Out</th>
<th>Total Time</th>
</tr>
</thead>
<tbody>
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td><a href=editTime.php?id=<?php echo $row['id'];?>>Edit</a></td>
<td><?php echo date('m/d/Y', strtotime($row['date']))?></td>
<td><?php echo($row['department'])?></td>
<td><?php echo date('g:i A', strtotime($row['t_in']))?></td>
<td><?php echo date('g:i A', strtotime($row['t_out']))?></td>
<td><?php $t_total = strtotime($row['t_out']) - strtotime($row['t_in']) ; echo gmdate('H:i', $t_total);?></td>
</tr>
</tbody>
<?php
}
?>
<tfoot>
<tr><td colspan='6'><span>Total time worked in <?php echo date('F')?>: <?php echo gmdate('H:i', $timeMonth);?></span></td></td>
<tr><td colspan='6'><span>Total time worked Year to Date: <?php echo gmdate('H:i', $timeYear);?></span></td></td>
</tfoot>
</table>
Thanks!