这就是我最终做到的方式
<?php
$query = "SELECT * from stats where user_id='".$nameID."' $where order by week desc";
$result = mysql_query($query) or die(mysql_error());
$worked_week = mysql_num_rows($result);
if(mysql_num_rows($result)) {
$k = 1;
while ($row_stats = mysql_fetch_array($result))
{
// Total Section //
$total_worked_hours=$total_worked_hours+$row_stats['worked_hours'];
$total_sales=$total_sales+$row_stats['sales'];
$total_sales=number_format($total_sales,2,'.','');
$total_facials=$total_facials+$row_stats['facials'];
$total_double_facials=$total_double_facials+$row_stats['double_facials'];
$total_classes=$total_classes+$row_stats['classes'];
$total_faces_viewed=$total_faces_viewed+$row_stats['faces_viewed'];
$total_interviews=$total_interviews+$row_stats['interviews'];
$total_recruits=$total_recruits+$row_stats['recruits'];
///
$k++;
}
// Percentage Section //
$perc_worked_hours = $total_worked_hours / $worked_week;
$perc_sales = $total_sales / $worked_week;
$perc_facials = $total_facials / $worked_week;
$perc_double_facials = $total_double_facials / $worked_week;
$perc_classes = $total_classes / $worked_week;
$perc_faces_viewed = $total_faces_viewed / $worked_week;
$perc_interviews = $total_interviews / $worked_week;
$perc_recruits = $total_recruits / $worked_week;
// round up
$perc_worked_hours=number_format($perc_worked_hours,0,'.','');
$perc_sales=number_format($perc_sales,2,'.','');
$perc_facials=number_format($perc_facials,0,'.','');
$perc_double_facials=number_format($perc_double_facials,0,'.','');
$perc_classes=number_format($perc_classes,0,'.','');
$perc_faces_viewed=number_format($perc_faces_viewed,0,'.','');
$perc_interviews=number_format($perc_interviews,0,'.','');
$perc_recruits=number_format($perc_recruits,0,'.','');
// END