2014-04-10 3 views
0

직원들이 시계를 넣을 수있는 시간 제한 시스템을 편집 중이며 지난 7 일 동안의 총 시간을 표시하려고합니다.하지만 코드는 조금 뒤죽박죽입니다. 어떻게 접근하는지 알아내는 데 어려움이 있습니다. 누가 나 좀 도와주고 싶어?지난 7 일 동안의 총 시간 표시

 <?php 
    // check if we have a report to generate 
    if ($_GET['action'] == "generate") { 
     // get name 
     $sql = "select name from employees where id = " . $_GET['employee_id'] . " limit 1"; 
     $result = mysql_query($sql) or die($sql); 
     $row = mysql_fetch_assoc($result); 
     extract($row); 
     // maybe need to edit this to get a better idea of time 
     $sql = "select unix_timestamp(time_in) as time_i, unix_timestamp(time_out) as time_o, timediff(time_out, time_in) as time_diff from time where employee_id = " . 
      $_GET['employee_id'] . " and time_out is not null and time_in between '" . $_GET['date_from'] . "' and '" . $_GET['date_to'] . " 23:59:59' and " . 
      "date_format(time_out, '%c%d%Y') = date_format(time_in, '%c%d%Y') order by time_i asc"; 
     $result = mysql_query($sql) or die($sql); 
     echo "<h1>TimeClock Report for $name</h1>\n"; 
     echo "<table cellpadding=\"4\" cellspacing=\"6\">\n"; 
     echo "<tr><th align=\"center\"><u>Date</u></th><th align=\"center\"><u>Clock In Time</u></th><th align=\"center\"><u>Clock Out Time</u></th><th align=\"center\"><u>Total Time</u></th></tr>\n"; 
     $current_time = time(); 
     $new_time = $current_time; 
     while ($row = mysql_fetch_array($result)) { 
      echo "<tr>"; 
      echo "<td align=\"center\">" . date("M jS", $row['time_i']) . "</td>"; 
      echo "<td align=\"center\">" . date("g:i:s A", $row['time_i']) . "</td>"; 
      echo "<td align=\"center\">" . date("g:i:s A", $row['time_o']) . "</td>"; 
      echo "<td align=\"center\">" . $row['time_diff'] . "</td>"; 
      echo "</tr>\n"; 
      $hrs = substr($row['time_diff'], 0, 2); 
      $min = substr($row['time_diff'], 3, 2); 
      $sec = substr($row['time_diff'], 6, 2); 
      $new_time += $sec; 
      $new_time += ($min * 60); 
      $new_time += ($hrs * 60 * 60); 
     } 
     echo "</table>\n"; 
     $date_diff = $new_time - $current_time; 
     $fullDays = floor($date_diff/(60*60*24)); 
     $fullHours = floor(($date_diff-($fullDays*60*60*24))/(60*60)); 
     $fullMinutes = floor(($date_diff-($fullDays*60*60*24)-($fullHours*60*60))/60); 
     $fullHours = $fullHours + ($fullDays * 24); 
     echo "<strong><u>Total:</u></strong> $fullHours hours $fullMinutes mins\n"; 
    } 
?> 

답변

0

는 지금까지 내가 말할 수있는 time_i, time_o와 시간() PHP 함수는 모든 유닉스 타임 스탬프를 반환합니다. 그래야 작동합니다.

$totalSecondsLast7Days = 0; 
    while ($row = mysql_fetch_array($result)) { 
     echo "<tr>"; 
     echo "<td align=\"center\">" . date("M jS", $row['time_i']) . "</td>"; 
     echo "<td align=\"center\">" . date("g:i:s A", $row['time_i']) . "</td>"; 
     echo "<td align=\"center\">" . date("g:i:s A", $row['time_o']) . "</td>"; 
     echo "<td align=\"center\">" . $row['time_diff'] . "</td>"; 
     echo "</tr>\n"; 
     $hrs = substr($row['time_diff'], 0, 2); 
     $min = substr($row['time_diff'], 3, 2); 
     $sec = substr($row['time_diff'], 6, 2); 
     $new_time += $sec; 
     $new_time += ($min * 60); 
     $new_time += ($hrs * 60 * 60); 

     // TO TRACK THE TIME FOR THE LAST 7 DAYS 
     // I use time_i here but maybe you want to use time_o 
     if ($row['time_i'] + 60*60*24*7 > $current_time) 
     { 
      $totalSecondsLast7Days += ($sec + $min*60 + $hrs*60*60); 
     } 
    } 

그런 다음 가장 적합한대로 표시합니다.

echo "<strong><u>Last 7 days:</u></strong> $totalSecondsLast7Days seconds\n"; 
관련 문제