CODE
function elapsedtime($sec) {
$days = floor($sec / 86400);
$hrs = floor(bcmod($sec,86400)/3600);
$mins = round(bcmod(bcmod($sec,86400),3600)/60);
if ($days > 20)
$tstring = $days . "d ";
if ($hrs > 0)
$tstring.=$hrs . " hours ";
if ($mins>0) {
if ($mins<10 && $hrs>0)
$tstring.="0";
$tstring.=$mins . " minutes";
}
return $tstring;
}
// Make the query.
$query = "SELECT * FROM timesheet WHERE username = '$username' ORDER BY date";
$result = @mysql_query ($query); // Run the query.
/* read the beginning and end times in from the database prior to this*/
$et = elapsedtime(($row['lunch'] - ($row['clockin']) + ($row['clockout'] - ($row['back_lunch']))));
echo "<center><b><font color = 'blue'>Timecard display for $username</font></center></b><br>";
// Table header.
echo '<table align="center" cellspacing="0" cellpadding="5">
<tr>
<td align="left"><b>Date</b></td>
<td align="left"><b>Clock in:</b></td>
<td align="left"><b>Out to lunch:</b></td>
<td align="left"><b>Back from lunch:</b></td>
<td align="left"><b>Clock out:</b></td>
<td align="left"><b>Total hours for the day:</b></td>
</tr>';
// Fetch and print all the records.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
print <<<EOF
<tr>
<td align="left">{$row['date']}</td>
<td align="left">{$row['clockin1']}</td>
<td align="left">{$row['lunch1']}</td>
<td align="left">{$row['back_lunch1']}</td>
<td align="left">{$row['clockout1']}</td>
<td align="left">$et</td>[/b]
</tr>
EOF;
}
echo '</table>';
mysql_free_result ($result); // Free up the resources.
mysql_close(); // Close the database connection.
$days = floor($sec / 86400);
$hrs = floor(bcmod($sec,86400)/3600);
$mins = round(bcmod(bcmod($sec,86400),3600)/60);
if ($days > 20)
$tstring = $days . "d ";
if ($hrs > 0)
$tstring.=$hrs . " hours ";
if ($mins>0) {
if ($mins<10 && $hrs>0)
$tstring.="0";
$tstring.=$mins . " minutes";
}
return $tstring;
}
// Make the query.
$query = "SELECT * FROM timesheet WHERE username = '$username' ORDER BY date";
$result = @mysql_query ($query); // Run the query.
/* read the beginning and end times in from the database prior to this*/
$et = elapsedtime(($row['lunch'] - ($row['clockin']) + ($row['clockout'] - ($row['back_lunch']))));
echo "<center><b><font color = 'blue'>Timecard display for $username</font></center></b><br>";
// Table header.
echo '<table align="center" cellspacing="0" cellpadding="5">
<tr>
<td align="left"><b>Date</b></td>
<td align="left"><b>Clock in:</b></td>
<td align="left"><b>Out to lunch:</b></td>
<td align="left"><b>Back from lunch:</b></td>
<td align="left"><b>Clock out:</b></td>
<td align="left"><b>Total hours for the day:</b></td>
</tr>';
// Fetch and print all the records.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
print <<<EOF
<tr>
<td align="left">{$row['date']}</td>
<td align="left">{$row['clockin1']}</td>
<td align="left">{$row['lunch1']}</td>
<td align="left">{$row['back_lunch1']}</td>
<td align="left">{$row['clockout1']}</td>
<td align="left">$et</td>[/b]
</tr>
EOF;
}
echo '</table>';
mysql_free_result ($result); // Free up the resources.
mysql_close(); // Close the database connection.
I'm guessing the $et variable won't display because it's not data that is kept in the database, but I'm not sure.
