Jump to content

getting Multiplication value in a loop


mraza

Recommended Posts

hi i need to get value after Multiplication in a loop as total, plz how can i do that here is my  code

					

while ($row = mysql_fetch_array($name)) {?>
<td><?php echo  $row['service']; ?></td>
<td><?php echo $result['qty'] ; ?></td>
<td><?php echo $total = ($result['qty'] * $row['price']); ?></td>
<?php 	} ?>

i need to get $total of sum after loop, currently it shows only individual.. thanks for any help..

Regards

Link to comment
https://forums.phpfreaks.com/topic/210921-getting-multiplication-value-in-a-loop/
Share on other sites

You can add each total while in the loop to keep a running total, then echo it when the loop completes.

while ($row = mysql_fetch_array($name)) {?>
<td><?php echo  $row['service']; ?></td>
<td><?php echo $result['qty'] ; ?></td>
<td><?php echo $total = ($result['qty'] * $row['price']); ?></td>
$running += $total
<?php
}
echo $running;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.