i have this function to show the user the items he has in his shopping cart:
function listCart($login_user) {
$sql = "SELECT * FROM cart WHERE email='$login_user' ORDER BY id";
$rs=$this->bd->executeSQL($sql);
$n=0;
$count=0;
$items=mysql_num_rows($rs);
if ($items >= 1 ) {
echo "Select an item to erase it or modify it's quantity.<br><br>";
echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" class=\"caixas\"><tr>
<td class=\"titulo\">Select</td>
<td class=\"titulo\">Qty</td>
<td class=\"titulo\">Code</td>
<td class=\"titulo\">Type</td>
<td class=\"titulo\">Model</td>
<td class=\"titulo\">Price</td>
<td class=\"titulo\">Subtotal</td></tr>";
echo "<tr bgcolor=\"#FFFFFF\">";
while(mysql_fetch_row($rs)) {
$bgcolor = ($count++ % 2) ? "#FFFFFF" : "#E9E9EC";
$subtotal = mysql_result($rs, $n, "price") * mysql_result($rs, $n, "qty");
echo "<td bgcolor=\"$bgcolor\"><a href=\"index.php?page=modify&action=see
&id=".mysql_result($rs, $n, "id")."&type=".mysql_result($rs, $n, "type")."
&model=".mysql_result($rs, $n, "model")."&code=".mysql_result($rs, $n, "code")."
&price=".mysql_result($rs, $n, "price")."&qty=".mysql_result($rs, $n, "qty")."\">
<img src=\"imagens/botoes/seta.gif\" border=\"0\" width=\"12\" height=\"10\"></td>
<td bgcolor=\"$bgcolor\">".mysql_result($rs, $n, "qty")."</b>
<td bgcolor=\"$bgcolor\">".mysql_result($rs, $n, "code")."</b></td>
<td bgcolor=\"$bgcolor\">".mysql_result($rs, $n, "type")."</td>
<td bgcolor=\"$bgcolor\">".mysql_result($rs, $n, "model")."</td>
<td bgcolor=\"$bgcolor\" align=\"center\">".mysql_result($rs, $n, "price")." €</td>
<td bgcolor=\"$bgcolor\" align=\"center\">$subtotal €</td>";
echo "</tr>";
$n++;
}
echo "</table>";
echo "<br>";
echo "<table width=\"15%\" align=\"right\" cellspacing=\"1\" cellpadding=\"0\" class=\"caixas\">
<tr><td class=\"titulo\">Total</td></tr>
<tr><td class=\"caixa\" align=\"right\"><b>$total €</b></td></tr>
</table>";
echo "<br><br><br>";
echo "<table width=\"100%\" border=\"0\"><tr><td><a href=\"index.php?page=cart&action=erase\">
<img src=\"imagens/botoes/delete_cart.gif\" width=\"150\" height=\"30\" border=\"0\"></a></td>
<td align=\"right\"><a href=\"index.php?page=order&action=order\">
<img src=\"imagens/botoes/checkout_order.gif\" width=\"150\" height=\"30\" border=\"0\"></a>
</td></tr></table>";
} else {
echo "The shopping cart is empty.";
}
}
i have an echo for a total in a table as you can see but the problem is that i don't know how to make $total be the sum of all $subtotal.
can you help me with this? i'm sure it is very easy but i can seem to find the way right now.
thanks in advance.