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!

Multiplying fields from a dynamic table

Status
Not open for further replies.

blasterstudios

Technical User
Dec 30, 2004
128
US
How would I go about performing calculations such as multiplying to fields in the same row in my dynamic table?

here is some sample code:
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 echo $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 fields i want to multiply should be like this:
Code:
$itemprice = $row_invoicedetails['itemprice'];
$quantity = $row_invoicedetails['quantity'];
$discount = (1 - $row_invoicedetails['discount']);
$rowtotal = (($itemprice * $quantity)*($discount));

This calculation only does the first row, then repeats the result for the remaining rows.
 
ok, sorry, i figured it out, all i need to do is insert my forumula in the table where the data is repeated. awesome.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top