while循环记录总数

i have this code

while($row=mysql_fetch_array($qu2)){
    $login_time=$row[login_time];
    $logout_time=$row[logout_time];
    $totlawork=($logout_time)-($login_time);
    $lossawork=($login_time)-('08:00:00');   

    echo '<tr>';
    echo '<td class="xtd"><div align="center">'.$cnt.'</div></td>';
    echo '<td class="xtd"><div align="center">'.$row[full_name] .'</div></td>';
    echo '<td class="xtd"><div align="center">'.$row[salary].'</div></td>';
    echo'<td class="xtd"><div align="center">'.$totlawork.'</div></td>';
    echo '<td class="xtd"><div align="center">'.$lossawork.'</div></td>';
    echo '</tr>';

    $cnt++;
}

i wont to get sum of $lossawork on all record how can i do this

$lossawork_total = 0; // set total to 0
while($row=mysql_fetch_array($qu2)){
    $login_time=$row[login_time];
    $logout_time=$row[logout_time];
    $totlawork=($logout_time)-($login_time);
    $lossawork=($login_time)-('08:00:00');     
    echo '<tr>';
    echo '<td class="xtd"><div align="center">'.$cnt.'</div></td>';
    echo '<td class="xtd"><div align="center">'.$row[full_name] .'</div></td>';
    echo '<td class="xtd"><div align="center">'.$row[salary].'</div></td>';
    echo'<td class="xtd"><div align="center">'.$totlawork.'</div></td>';
    echo '<td class="xtd"><div align="center">'.$lossawork.'</div></td>';
    echo '</tr>';
    $cnt++;
    $lossawork_total += $lossawork; // add this lossawork to total
}
echo $lossawork_total; // display total

In the end of your loop add the lossawork to anothr counter and show that counter on the page, it will add all the lossawork together for you while the loop runs.

use a variable out side of the while loop, here ($sum)

$sum = 0;

while(...){
...
...
...
...

$sum += $lossawork;

}

echo $sum;

More code is required in the question to answer it completely, but based on my understanding of the question, what you want can be acheived as follows:

//Declare a variable to store the sum and initialize it to 0
$sum_lossawork = 0;

while($row=mysql_fetch_array($qu2)){

    ...
    ...
    $lossawork= ...

    //For each row in the data set add $lossawork to the sum
    $sum_lossawork += $lossawork;

    ...
    ... 

    $cnt++;
}

echo $sum_lossawork;