Hi all,
I have a page which shows a customers order, what products they have bought, the quantity, and the price of the item.
I can loop through the db to get all the items the customer bought, and I can get the value of these items and * it by the quantity to get the total value for both those items.
However, I am having problems getting the total amount for that order.
Here is the code that gets all the items from an order:
<?php do { ?>
<tr>
<td><?php echo $row_getitems['Item_Name']; ?></td>
<td><?php echo $row_getitems['Quantity']; ?><td>
<td><?php echo $row_getitems['Sell_Price']; ?></td>
<td><?php echo $ordercost=$row_getitems['Quantity'] * $row_getitems['Sell_Price'];?>
<td>
</tr>
<?php } while ($row_getitems = mysql_fetch_assoc $getitems)); ?>
Which could output something like this:
ItemName Quantity ItemPrice Cost
Tie 2 3.50 7.00
Socks 4 3.00 12.00
I now want to loop through the $ordercost to get the total for the whole order, but I can't seem to get it right, so far I have written:
<?php
// loop number of items
$total = 0;
for($k=0; $k < count($row_getitems = mysql_fetch_assoc($getitems)); $k++) {
$total += $ordercost[$k]; } echo "Total = " . $total; ?>
I am not sure what to do, please can anyone suggest something?
Thank you
sipps
I have a page which shows a customers order, what products they have bought, the quantity, and the price of the item.
I can loop through the db to get all the items the customer bought, and I can get the value of these items and * it by the quantity to get the total value for both those items.
However, I am having problems getting the total amount for that order.
Here is the code that gets all the items from an order:
<?php do { ?>
<tr>
<td><?php echo $row_getitems['Item_Name']; ?></td>
<td><?php echo $row_getitems['Quantity']; ?><td>
<td><?php echo $row_getitems['Sell_Price']; ?></td>
<td><?php echo $ordercost=$row_getitems['Quantity'] * $row_getitems['Sell_Price'];?>
<td>
</tr>
<?php } while ($row_getitems = mysql_fetch_assoc $getitems)); ?>
Which could output something like this:
ItemName Quantity ItemPrice Cost
Tie 2 3.50 7.00
Socks 4 3.00 12.00
I now want to loop through the $ordercost to get the total for the whole order, but I can't seem to get it right, so far I have written:
<?php
// loop number of items
$total = 0;
for($k=0; $k < count($row_getitems = mysql_fetch_assoc($getitems)); $k++) {
$total += $ordercost[$k]; } echo "Total = " . $total; ?>
I am not sure what to do, please can anyone suggest something?
Thank you
sipps