다음 코드를 사용하여 데이터베이스의 데이터에서 테이블을 생성하고 있습니다. 직원별로 데이터를 그룹화합니다. 필자가 필요로하는 것은 각 직원 테이블 끝에 마지막 네 열의 합계를 표시하는 것입니다. The Hours, OT, Travel 및 TOT 열.MYSQL PHP 쿼리에서 표에 합계를 추가하십시오.
코드 :
$current_user_name = false;
while($row = mysql_fetch_array($result)) {
// listing a new employee? Output the heading, start the table
if ($row['user_name'] != $current_user_name) {
if ($current_user_name !== false)
echo '</table>'; echo '[divider_padding]';// if we're changing employee, close the table
echo '
<h5>'.$row['last_name'].', '.$row['first_name'].'</h5>[minimal_table]
<table>
<tr>
<th>Date</th>
<th class="tableleft">Description</th>
<th class="tableleft">Job</th>
<th class="tableleft">Activity</th>
<th class="tableleft">Comments</th>
<th class="tableright">Hours</th>
<th class="tableright">OT</th>
<th class="tableright">Travel</th>
<th class="tableright">TOT</th>
</tr>';
$current_user_name = $row['user_name'];
}
// output the row of data
echo '<tr>
<td style="width:75px">'.$row['labor_date'].'</td>
<td class="tableleft">'.$row['description'].'</td>
<td class="tableleft">'.strtoupper($row['job']).'</td>
<td class="tableleft">'.$row['activity'].'</td>
<td class="tableleft">'.$row['comments'].'</td>
<td class="tableright">'.$row['rthours'].'</td>
<td class="tableright">'.$row['othours'].'</td>
<td class="tableright">'.$row['trthours'].'</td>
<td class="tableright">'.$row['tothours'].'</td>
</tr>
';}
echo '</table>[/minimal_table]'; // close the final table
}
?>
나는 몇 가지 테스트를 시도한 후 끼 었어이 알아낼 수 없습니다. 어떤 도움을 주시면 감사하겠습니다
$result = mysql_query("SELECT * FROM data WHERE labor_date BETWEEN '$start' AND '$end' Order by last_name, labor_date ASC");
:
이
데이터를 수집하는 쿼리입니다.
... '총 $ rthours + = $의 다음 행 ['rthours를 ']', 출력 어떤 특정 직원과 일을 마치면 다른 곳에서. –
예, 작동합니다. 어디에 넣을 지 알 수 없습니다. 코드를 배치 할 때마다 각 테이블의 맨 아래에 있지 않습니다. 나는 데이터 섹션의 출력의 닫는 테이블 행 후에 시도했다. 코드 상단에있는 닫기 괄호 앞에 시도했습니다. – Lawrence