Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting sum of repeat region

Status
Not open for further replies.

blasterstudios

Technical User
Dec 30, 2004
128
US
How do i get the sum of one of my columns in my repeat region?
 
Yeah, sorry.

It's basically a repeat region (vertical loop) that pulls from the SQL database. i have one column that finds the total of each row (it's for an invoice). Finally, i'd like a total of the total column. here's the code for the repeat region:
Code:
<table width="660" border="0" align="center" cellpadding="2" cellspacing="0" bordercolor="#333333" class="invdetails">
        <tr bgcolor="#CCCCCC" class="invdetails">
          <td class="invdetails"><span style="font-size: x-small; font-weight: bold">Product Name</span></td>
          <td width="70" class="invdetails"><span style="font-size: x-small; font-weight: bold">Unit Price </span></td>
          <td width="50" class="invdetails" style="font-size: x-small"><div align="center" style="font-weight: bold">Quantity</div></td>
          <td width="90" class="invdetails"><span style="font-size: x-small; font-weight: bold">Per</span></td>
          <td width="60" class="invdetails"><span style="font-size: x-small; font-weight: bold">Discount</span></td>
          <td width="60" class="invdetails"><div align="right" style="font-weight: bold"><span style="font-size: x-small">Item Total </span></div></td>
        </tr>
        <?php do { ?>
        <tr bgcolor="<?php
if($SSAdv_m1%$SSAdv_change_every1==0 && $SSAdv_m1>0){
$SSAdv_k1++;
}
print $SSAdv_colors1[$SSAdv_k1%count($SSAdv_colors1)];
$SSAdv_m1++;
?>"  class="invdetails">
          <td class="invdetails"><span style="font-size: x-small"><?php echo $row_invoicedetails['productid']; ?></span></td>
          <td width="70" class="invdetails"><span style="font-size: x-small"><span style="font-size: x-small">$<?php echo number_format($row_invoicedetails['itemprice'],2,'.',','); ?></span></span></td>
          <td width="50" class="invdetails" style="font-size: x-small"><div align="center"><?php echo $row_invoicedetails['quantity']; ?></div></td>
          <td width="90" class="invdetails"><span style="font-size: x-small"><?php echo $row_invoicedetails['per']; ?></span></td>
          <td width="60" class="invdetails"><span style="font-size: x-small"><?php echo $row_invoicedetails['discount']; ?></span></td>
          <td width="60" class="invdetails"><div align="right" style="font-size: x-small; font-weight: bold">$<?php 
		   $itemprice = $row_invoicedetails['itemprice'];
		   $quantity = $row_invoicedetails['quantity'];
		   $discount = (1 - $row_invoicedetails['discount']);
		   $rowtotal = (($itemprice * $quantity)*($discount));
		   printf("%01.2f", $rowtotal); ?></div></td>
        </tr>
<tr <?php 
// technocurve arc 3 php bv block2/3 start
echo " style=\"background-color:$color\"";
// technocurve arc 3 php bv block2/3 end
?>>
          <td colspan="6" class="invdetails"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="3%" align="center" valign="middle"><img src="images/notesarrow.gif" width="10" height="10"></td>
              <td width="97%"><span style="font-size: x-small"><?php echo $row_invoicedetails['notes']; ?></span></td>
            </tr>
          </table>            </td>
        </tr>
<?php 
// technocurve arc 3 php bv block3/3 start
if ($color == $color1) {
	$color = $color2;
} else {
	$color = $color1;
}
// technocurve arc 3 php bv block3/3 end
?>
<?php } while ($row_invoicedetails = mysql_fetch_assoc($invoicedetails)); ?>
      </table>

The reason i didn't want to paste this is because their is a lot of extra stuff in here to make the row sets of 2 alternate in color.

anyway, my total will not be inside this table, but i want to show it later on the page in a total invoice price spot. understand?
 
Before you start building the table:
Code:
$total_total = 0;
Each time you get the $rowtotal:
Code:
$rowtotal = (($itemprice * $quantity)*($discount));
$total_total += $rowtotal;
The display the $total_total where ever you want after the table is built.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top