i am trying to add values within in a while loop that is within more loops, i the following code works how i want it to, however it adds the total hours from each group to the next groups total hours. how can i fix this?
$result = mysql_query("SELECT * FROM employees ") or die(mysql_error());
while($row = mysql_fetch_array($result)){
$id = $row['id'];
$first = $row['first'];
$last = $row['last'];
$rate = $row['rate'];
$phone = $row['phone'];
$curWeek = date('W');
$results_w = mysql_query("SELECT DISTINCT eid FROM logs WHERE eid='$id' AND week='$curWeek' ORDER BY lid ASC") or die(mysql_error());
while($rows = mysql_fetch_array($results_w)){
?>
<table align="center" width="500" border="1" cellspacing="0" cellpadding="6">
<tr>
<td style="padding-left:10px; padding-right:10px;" colspan="5">
<div style="float:left"><? echo $first.' '.$last; ?> - Week #<? echo date('W'); ?></div>
<div style="float:right"><? echo '('.$phone[0].$phone[1].$phone[2].') '.$phone[3].$phone[4].$phone[5].' - '.$phone[6].$phone[7].$phone[8].$phone[9]; ?></div>
</td>
</tr>
<?
$results = mysql_query("SELECT DISTINCT session FROM logs WHERE eid='$id' AND week='$curWeek' ORDER BY lid ASC") or die(mysql_error());
while($rowss = mysql_fetch_array($results)){
$testing = array();
$session_row = $rowss['session'];
$resultss = mysql_query("SELECT lid FROM logs WHERE session='$session_row' ORDER BY lid ASC") or die(mysql_error());
while($rowz = mysql_fetch_array($resultss)){
$logID = $rowz['lid'];
array_push($testing,$rowz['lid']);
}
$a = mysql_query("SELECT * FROM logs WHERE lid='$testing[0]' ") or die(mysql_error());
$aD = mysql_fetch_array($a);
$b = mysql_query("SELECT * FROM logs WHERE lid='$testing[1]' ") or die(mysql_error());
$bD = mysql_fetch_array($b);
$start_min = ($aD['hour'] * 60) + $aD['minute'];
$end_min = ($bD['hour'] * 60) + $bD['minute'];
$total_min = $end_min - $start_min;
$total_hour = $total_min / 60;
?>
<tr>
<td><? echo $aD['weekday']; ?></td>
<td><? print( date("g:i A", strtotime($aD['hour'].':'.$aD['minute'])) ); ?></td>
<td><? print( date("g:i A", strtotime($bD['hour'].':'.$bD['minute'])) ); ?></td>
<td><? echo $total_hour; ?> Hours</td>
</tr>
<?}
$total_w += $total_hour;
$total_bt = $total_w * 7.00;
$total_t = $total_bt * .0765;
$total = $total_bt - $total_t;
?>
<tr>
<td colspan="2" rowspan="4"></td>
<td align="right">Total Hours:</td>
<td><? echo $total_w;?> Hours</td>
</tr>
<tr>
<td align="right">Total Before Tax:</td>
<td>$<? echo $total_bt;?></td>
</tr>
<tr>
<td align="right">Tax Paid:</td>
<td>$<? echo $total_t;?></td>
</tr>
<tr>
<td align="right">Check Total:</td>
<td>$<? echo $total;?></td>
</tr>
</table><br />
<?
}
}
?>
$result = mysql_query("SELECT * FROM employees ") or die(mysql_error());
while($row = mysql_fetch_array($result)){
$id = $row['id'];
$first = $row['first'];
$last = $row['last'];
$rate = $row['rate'];
$phone = $row['phone'];
$curWeek = date('W');
$results_w = mysql_query("SELECT DISTINCT eid FROM logs WHERE eid='$id' AND week='$curWeek' ORDER BY lid ASC") or die(mysql_error());
while($rows = mysql_fetch_array($results_w)){
?>
<table align="center" width="500" border="1" cellspacing="0" cellpadding="6">
<tr>
<td style="padding-left:10px; padding-right:10px;" colspan="5">
<div style="float:left"><? echo $first.' '.$last; ?> - Week #<? echo date('W'); ?></div>
<div style="float:right"><? echo '('.$phone[0].$phone[1].$phone[2].') '.$phone[3].$phone[4].$phone[5].' - '.$phone[6].$phone[7].$phone[8].$phone[9]; ?></div>
</td>
</tr>
<?
$results = mysql_query("SELECT DISTINCT session FROM logs WHERE eid='$id' AND week='$curWeek' ORDER BY lid ASC") or die(mysql_error());
while($rowss = mysql_fetch_array($results)){
$testing = array();
$session_row = $rowss['session'];
$resultss = mysql_query("SELECT lid FROM logs WHERE session='$session_row' ORDER BY lid ASC") or die(mysql_error());
while($rowz = mysql_fetch_array($resultss)){
$logID = $rowz['lid'];
array_push($testing,$rowz['lid']);
}
$a = mysql_query("SELECT * FROM logs WHERE lid='$testing[0]' ") or die(mysql_error());
$aD = mysql_fetch_array($a);
$b = mysql_query("SELECT * FROM logs WHERE lid='$testing[1]' ") or die(mysql_error());
$bD = mysql_fetch_array($b);
$start_min = ($aD['hour'] * 60) + $aD['minute'];
$end_min = ($bD['hour'] * 60) + $bD['minute'];
$total_min = $end_min - $start_min;
$total_hour = $total_min / 60;
?>
<tr>
<td><? echo $aD['weekday']; ?></td>
<td><? print( date("g:i A", strtotime($aD['hour'].':'.$aD['minute'])) ); ?></td>
<td><? print( date("g:i A", strtotime($bD['hour'].':'.$bD['minute'])) ); ?></td>
<td><? echo $total_hour; ?> Hours</td>
</tr>
<?}
$total_w += $total_hour;
$total_bt = $total_w * 7.00;
$total_t = $total_bt * .0765;
$total = $total_bt - $total_t;
?>
<tr>
<td colspan="2" rowspan="4"></td>
<td align="right">Total Hours:</td>
<td><? echo $total_w;?> Hours</td>
</tr>
<tr>
<td align="right">Total Before Tax:</td>
<td>$<? echo $total_bt;?></td>
</tr>
<tr>
<td align="right">Tax Paid:</td>
<td>$<? echo $total_t;?></td>
</tr>
<tr>
<td align="right">Check Total:</td>
<td>$<? echo $total;?></td>
</tr>
</table><br />
<?
}
}
?>