How to get total in loop?
Posted: Sun Nov 21, 2010 1:13 pm
Hi how do I get the total(sum of qty * price of all items) in this loop?
In this example I need to get...$total = 340
table structure:
id | name | qty | price
1 | php | 5 | 20
2 | js |10 | 30
3 | html |1 | 40
In this example I need to get...$total = 340
table structure:
id | name | qty | price
1 | php | 5 | 20
2 | js |10 | 30
3 | html |1 | 40
Code: Select all
while($row = mysql_fetch_assoc($get))
{
<tr>
<td>$row['name']</td>
<td>$row['qty']</td>
<td>$row['price']</td>
<td>$row['qty'] * $row['price'] </td>
</tr>
}
<tr>
<td colspan=4>$total</td>
</tr>