M
Mr E
Guest
i have a shopping basket page and have got a running total of the prices together by multiplying the price by the quantity ordered.
however i do not know how to add all them totals together to get the final total. i'm assuming it would require some sort of loop but not sure completely how to do it.
this is my code
<?php
echo ("<table border=1>");
echo ("<th id='tablestyle'> Door Name</th>");
echo ("<th id='tablestyle'> Quantity</th>");
echo ("<th id='tablestyle'>Individual Price</th>");
echo ("<th id='tablestyle'>Image</th>");
echo ("<th id='tablestyle'>Sub Total</th>");
echo ("<tr>");
foreach ($_SESSION as $key=>$val)
{
$index = stripos($val, "+");
$quantity = substr($val, 0, $index);
$price = substr($val,$index+1);
$sql = mysql_query("SELECT Thumbimage, DoorName FROM tblpricelist where DoorName = $index");
$image = $row['Thumbimage'];
echo "<td id='tablestyle2'> $key </td>";
echo "<td id='tablestyle2'> $quantity </td>";
echo "<td id='tablestyle2'> £$price </td>";
echo "<td id='tablestyle2'><img src='./thumb/". "$image"."'/></td>";
$sum_total=$quantity*$price;
echo "<td id='tablestyle2'>£$sum_total</td>";
$sum_total2=$sum_total+$sum_total;
echo "<td id='tablestyle2'>£$sum_total2</td>";
echo "</tr>";
}
echo ("</tr>");
echo ("</table>");
?>
</div>
as you can see my current method just simply add the total with itself (obviously not the right method)
however i do not know how to add all them totals together to get the final total. i'm assuming it would require some sort of loop but not sure completely how to do it.
this is my code
<?php
echo ("<table border=1>");
echo ("<th id='tablestyle'> Door Name</th>");
echo ("<th id='tablestyle'> Quantity</th>");
echo ("<th id='tablestyle'>Individual Price</th>");
echo ("<th id='tablestyle'>Image</th>");
echo ("<th id='tablestyle'>Sub Total</th>");
echo ("<tr>");
foreach ($_SESSION as $key=>$val)
{
$index = stripos($val, "+");
$quantity = substr($val, 0, $index);
$price = substr($val,$index+1);
$sql = mysql_query("SELECT Thumbimage, DoorName FROM tblpricelist where DoorName = $index");
$image = $row['Thumbimage'];
echo "<td id='tablestyle2'> $key </td>";
echo "<td id='tablestyle2'> $quantity </td>";
echo "<td id='tablestyle2'> £$price </td>";
echo "<td id='tablestyle2'><img src='./thumb/". "$image"."'/></td>";
$sum_total=$quantity*$price;
echo "<td id='tablestyle2'>£$sum_total</td>";
$sum_total2=$sum_total+$sum_total;
echo "<td id='tablestyle2'>£$sum_total2</td>";
echo "</tr>";
}
echo ("</tr>");
echo ("</table>");
?>
</div>
as you can see my current method just simply add the total with itself (obviously not the right method)