2016-03-22 16 views
0

Ich habe eine Situation, in der ich die Gesamtstunden für jeden Satz an jedem Tag berechnen muss. Aber ich habe viele Tage daran festgemacht. Ich versuche, wie unten ausgegeben zu werden:So erhalten Sie die Gesamtsumme der Stunden für jeden Tag

Day  Clock In Clock Out Total Hours(Hr) Total Hours Per Day(Hr) 
Monday  08:00  09:00  1.00          
      10:00  12:00  2.00   
      13:00  14:30  1.50    4.50 
Tuesday 08:30  10:00  1.50 
      15:00  17:50  2.83    4.33 
Wednesday 08:00  17:00  9.00    9.00 

            Total  17.83 

Ich habe versucht, zu kodieren und etwas Bemühung bis jetzt zu tun. Bitte helfen Sie mir Jungs. Werde es so sehr schätzen.

for($days=0;$days<3;$days++) { //get how many days 

$clocked_records_each_day = count($get_attendance_records); //get attendance     clock sets 

for($records=0; $records<$clocked_records_each_day; $records++) { 
$total_hour_per_set = $clocked_records_each_day[$records]['total_hour']; 
$total_hour_per_day = ??; 
$total_hour_overall = ??; 
//stuck until here 
//get the output and display 
} 

} 
+0

Können Sie zeigen, was sich in $ $ get_attendance_records befindet? – Aleeeeee

+0

Wie speichern Sie die Tabelle der Informationen? – SGR

+0

$ get_attendance_records enthält Zeilen für jeden Uhrsatz pro Tag. – EDDY

Antwort

1

Grundsätzlich gilt:

/* Init grand total: */ 
$total_hour_overall = 0; 

for($days=0;$days<3;$days++) { //get how many days 

    /* Init day subtotal at each for loop: */ 
    $total_hour_per_day = 0; 

    $clocked_records_each_day = count($get_attendance_records); //get attendance     clock sets 

    for($records=0; $records<$clocked_records_each_day; $records++) { 
     $total_hour_per_set = $clocked_records_each_day[$records]['total_hour']; 

     /* Increment day subtotal and grand total: */ 
     $total_hour_per_day += $clocked_records_each_day[$records]['total_hour']; 
     $total_hour_overall += $clocked_records_each_day[$records]['total_hour']; 

     /* Echo set total inside records for: */ 
     echo $total_hour_per_set; 
    } 

    /* Echo day subtotal inside days for: */ 
    echo $total_hour_per_day; 
} 

/* Echo grand total outside for loop: */ 
echo $total_hour_overall; 
+0

Große Antwort! Daumen hoch und vielen Dank! – EDDY

+0

Gern geschehen. – fusion3k

+0

Wie zeige ich das Ergebnis im Tabellenformat an? Das Problem liegt darin, dass $ total_hour_per_set in der $ records-Schleife angezeigt wird, aber $ total_hour_per_day außerhalb der $ records-Schleife angezeigt wird. Ich möchte sie in derselben Tabelle haben. – EDDY

1

Sie müssen es in zwei Teile tun, zuerst Summe alle auf, dann ist es angezeigt werden soll.

for($records=0; $records<$clocked_records_each_day; $records++) { 
    $total_hour_per_set = $clocked_records_each_day[$records]['total_hour']; 
    $total_hour_per_day[$clocked_records_each_day[$records]['day'][] = $total_hour_per_set 
    $total_hour_overall+= $total_hour_per_set; 
} 

So, jetzt haben Sie alle Daten, die Sie benötigen.

Und für jeden Tag können Sie

angezeigt
for($records=0; $records<$clocked_records_each_day; $records++) { 
    Display($total_hour_per_set = $clocked_records_each_day[$records]['total_hour']); 
    Display(array_sum($total_hour_per_day[$clocked_records_each_day[$records]['day'])); 
    Display($total_hour_overall+= $total_hour_per_set); 
} 

Dies setzt voraus, dass Sie eine Anzeige (...) Funktion.

Verwandte Themen