PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
desperado
Forum Commoner
Posts: 46 Joined: Wed Dec 10, 2008 8:49 am
Post
by desperado » Fri Jan 09, 2009 12:10 am
question: I would like to add up all the totals that are produced here. It loops through rows and gives me a total for each row. In red is my calculation for each row total.
Code: Select all
<?php do { ?>
<tr class="table_items">
<td class="table_items"><?php echo $row_DetailRS1['CTASKNAME']; ?></td>
<td class="table_items"><div align="right"><?php echo number_format($row_DetailRS1['YESTHRRATE'],2); ?></div></td>
<td class="table_items"><div align="right"><?php echo number_format($row_DetailRS1['NESTHRS'],2); ?></div></td>
<td class="table_items"><div align="right"><?php echo number_format($row_DetailRS1['YESTFLRATE'],2); ?></div></td>
<td class="table_items"><div align="right"><?php echo number_format($row_DetailRS1['NESTMUP'],2); ?></div></td>
<td class="table_items"><div align="right"><?php echo number_format($row_DetailRS1['NADJHRS'],2); ?></div></td>
<td class="table_items"><div align="right">[color=#BF0000]<?php echo number_format(($row_DetailRS1['YESTHRRATE'] * $row_DetailRS1['NESTHRS']) + ($row_DetailRS1['YESTFLRATE'] + ($row_DetailRS1['YESTFLRATE'] * $row_DetailRS1['NESTMUP'])),2); ?>[/color]</div></td>
<td class="table_items"> </td>
<td class="table_items"> </td>
<td class="table_items"> </td>
<td class="table_items"> </td>
<td class="table_items"> </td>
</tr>
<?php } while ($row_DetailRS1 = mysql_fetch_assoc($DetailRS1)); ?>
</table>
it looks like this:
So how do I add up the totals?
watson516
Forum Contributor
Posts: 198 Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario
Post
by watson516 » Fri Jan 09, 2009 12:17 am
How about something like this...
Code: Select all
$counter=0;
do
{
$equation=5+1;
...
$counter = $counter + $equation;
}while($x>$y);
echo $counter;
desperado
Forum Commoner
Posts: 46 Joined: Wed Dec 10, 2008 8:49 am
Post
by desperado » Fri Jan 09, 2009 12:06 pm
Of course... Thx!
Problem #2: Now I cant get
this to work:
REMOVED URL
I need to add the total number of hours
per task in the table at the bottom and put the result inside the "Actual Hours" column at the top. I tried another "do{...}while" loop within the main loop. It's commented out in red below. All it does is fill in the total result in the first cell.
I'm so confused....
Code: Select all
<?php
$grandtotal=0;
do { ?>
<tr class="table_items">
<td class="table_items"><?php echo $row_Estimates['CTASKNAME']; ?></td>
<td class="table_items"><div align="right"><?php echo number_format($row_Estimates['YESTHRRATE'],2); ?></div></td>
<td class="table_items"><div align="right"><?php echo number_format($row_Estimates['NESTHRS'],2); ?></div></td>
<td class="table_items"><div align="right"><?php echo number_format($row_Estimates['YESTFLRATE'],2); ?></div></td>
<td class="table_items"><div align="right"><?php echo number_format(($row_Estimates['NESTMUP'] * 100)); ?>%</div></td>
<td class="table_items"><div align="right"><?php
$total = ($row_Estimates['YESTHRRATE'] * $row_Estimates['NESTHRS']) + ($row_Estimates['YESTFLRATE'] + ($row_Estimates['YESTFLRATE'] * $row_Estimates['NESTMUP']));
echo number_format($total,2);
$grandtotal = $grandtotal + $total;
?></div></td>
<td class="table_items">
[color=#FF0000]<?php
// $taskID = $row_Estimates['TASKID'];
// $actualhourstotal=0;
// do {
// if ($row_ActualTime['TASKID'] = '$taskID'){
// $actualhours = ($row_ActualTime['NHRS']);
// $actualhourstotal = $actualhourstotal + $actualhours;
// }else{
// }
// } while ($row_ActualTime = mysql_fetch_assoc($ActualTime));
// echo number_format($actualhourstotal,2);
?> </td>[/color]
<td class="table_items"> </td>
<td class="table_items"> </td>
<td class="table_items"> </td>
<td class="table_items"> </td>
<td class="table_items"><?php echo $row_Estimates['TASKID']; ?></td>
</tr>
<?php } while ($row_Estimates = mysql_fetch_assoc($Estimates)); ?>
<tr><td> </td><td> </td><td> </td><td> </td><td> </td><td class="table_total"><div align="right"><?php echo number_format($grandtotal,2); ?></div></td>
<td> </td><td> </td><td> </td><td> </td>
<td> </td>
<td> </td></tr></table>
Last edited by
desperado on Fri Jan 09, 2009 3:37 pm, edited 1 time in total.
desperado
Forum Commoner
Posts: 46 Joined: Wed Dec 10, 2008 8:49 am
Post
by desperado » Fri Jan 09, 2009 3:36 pm
Never mind, my problem was the use of 2 different queries. merging them solved it.