Page 1 of 1

Sum of a dynamic sum?

Posted: Fri Jan 09, 2009 12:10 am
by desperado
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">&nbsp;</td>
      <td class="table_items">&nbsp;</td>
      <td class="table_items">&nbsp;</td>
      <td class="table_items">&nbsp;</td>
      <td class="table_items">&nbsp;</td>
    </tr>
    <?php } while ($row_DetailRS1 = mysql_fetch_assoc($DetailRS1)); ?>
</table>
it looks like this:

Image

So how do I add up the totals?

Re: Sum of a dynamic sum?

Posted: Fri Jan 09, 2009 12:17 am
by watson516
How about something like this...

Code: Select all

$counter=0;
do
{
    $equation=5+1;
    ...
    $counter = $counter + $equation;
}while($x>$y);
echo $counter;

Re: Sum of a dynamic sum?

Posted: Fri Jan 09, 2009 12:06 pm
by desperado
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">&nbsp;</td>
      <td class="table_items">&nbsp;</td>
      <td class="table_items">&nbsp;</td>
      <td class="table_items">&nbsp;</td>
      <td class="table_items"><?php echo $row_Estimates['TASKID']; ?></td>
    </tr>
    <?php } while ($row_Estimates = mysql_fetch_assoc($Estimates)); ?>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td class="table_total"><div align="right"><?php echo number_format($grandtotal,2); ?></div></td>
<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td></tr></table>

Re: Sum of a dynamic sum?

Posted: Fri Jan 09, 2009 3:36 pm
by desperado
Never mind, my problem was the use of 2 different queries. merging them solved it.