I have a loop that pulls timestamps from a database, converts them to hours:minutes:seconds echo's that then adds all of them together and echo's that as well. The problem I have is on the final loop it isn't doing any of the math. The code will pull the timestamps and convert them and even display the converted timestamps. It just won't do the calcualtions and then echo it.
example:
tim_start8:00
timend__8:15
total time 15 min
mikestart8:02
mikeend_____8:12
total time 10 min
jackstart8:05
jackend___8:17
complete total time 25 min
no total time for jack and complete total time should be 37 min
$query4="SELECT * FROM job_log WHERE $table_id=table_id";
$complete_total_time = 0;
$last_value = "";
$result4=mysql_query($query4);
while($row4 = mysql_fetch_assoc($result4)) {
if (preg_match('/Start Creation|Start Table PTG|Cutting - Begin|Begin 1st Proof|Proof Print - Begin|Start In-House Fix|Final Print - Begin|Start Outside Change/',$action6)){
$start_action = $time_table4;
$start_count++;}
if ($action6=="Pause"){
$pause_time = $time_table4;
$pause_count++;
$start_action1 = $pause_time - $start_action;}
if ($action6=="Resume"){
$resume_time = $time_table4;
$resume_count++;}
if (preg_match('/End Creation|Finish Table PTG|Cutting - End|End 1st Proof -OK|End 1st Proof - FIX|End In-House Fix|Final Print - End|End Outside Change/',$action6)){
$end_action = $time_table4;
$end_count++;
if ($end_count > $start_count){
$start_action = "0";
$start_count--;}
if ($resume_count < $pause_count){
$sec = ($end_action - $start_action) + $start_action1;
$total_seconds = $sec;
$hr = floor($sec/60/60);
$sec = $sec - $hr * 60 * 60;
$min = floor($sec/60);
$sec = $sec - $min * 60;
$total_time = sprintf("%02d:%02d:%02d", $hr, $min, $sec);
$start_count = "0";
$end_count = "0";
$pause_count = "0";
$resume_count = "0";
$pause_time = "0";
$resume_time = "0";
if ($total_time > "05:00:00" || $total_time <= "00:00:00"){echo "";}
else {echo "<center><table border = '0' cellspaceing = '0' cellpadding = '-1' width = '10%' bgcolor = '#999999'>";
echo "<tr><td align = 'center' width = '100%'>$total_time</td>";
echo "</tr></table></center>";
$complete_total_time += $total_seconds;}}
$sec = ($end_action - $resume_time) + ($pause_time - $start_action);
$total_seconds = $sec;
$hr = floor($sec/60/60);
$sec = $sec - $hr * 60 * 60;
$min = floor($sec/60);
$sec = $sec - $min * 60;
$total_time = sprintf("%02d:%02d:%02d", $hr, $min, $sec);
$start_count = "0";
$end_count = "0";
$pause_count = "0";
$resume_count = "0";
$pause_time = "0";
$resume_time = "0";
if ($total_time > "05:00:00" || $total_time <= "00:00:00"){echo "";}
else {echo "<center><table border = '0' cellspaceing = '0' cellpadding = '-1' width = '10%' bgcolor = '#999999'>";
echo "<tr><td align = 'center' width = '100%'>$total_time</td>";
echo "</tr></table></center>";
$complete_total_time += $total_seconds;}}
else{
echo "";}
{
$time_table4 = $row4['time'];
$employee_name5 = $row4['employee_id'];
$action6 = $row4['action'];
$showtime2 = date('m/d/y-h:i:s',$time_table4);
if ($showtime2=="12/31/69-06:00:00")
$showtime2 = "No Entry";
else
$showtime2 = date('m/d/y-h:i:s',$time_table4);
$query5 = "SELECT * FROM employees WHERE employee_id = '$employee_name5'";
$result5 = mysql_query($query5);
while($row5 = mysql_fetch_assoc($result5))
{
$employee_name5 = $row5['fname']." ".$row5['lname'];
if ($employee_name5=="")
$employee_name5 = "No Entry";
else
$employee_name5 = $row5['fname']." ".$row5['lname'];
}
$query6 = "SELECT * FROM job_actions WHERE action_id = '$action6'";
$result6 = mysql_query($query6);
while($row6 = mysql_fetch_assoc($result6))
{
$action6 = $row6['action_name'];
if ($action6=="")
$action6 = "No Entry";
else
$action6 = $row6['action_name'];
}
if($row['action_id'] != $last_value){
$last_value = $row['action_id'];}
}
echo "<center><table border = '0' cellspaceing = '0' cellpadding = '1' width = '100%' bgcolor = '#ffffff'>";
echo "<tr><td align = 'center' abbr = abbr_text width = '40%'>$table_id</td><td align = 'center' width = '20%'>$employee_name5</td><td align = 'center' width = '20%'>$showtime2</td><td align = center width = '25%'>$action6</td></tr>";
echo "</table></center>";
}
$sec = $complete_total_time;
$hr = floor($sec/60/60);
$sec = $sec - $hr * 60 * 60;
$min = floor($sec/60);
$sec = $sec - $min * 60;
$complete_total_time = sprintf("%02d:%02d:%02d", $hr, $min, $sec);
echo "$complete_total_time";