This semester to make a shopping site, most of them are finished, basically only the total price of the calculation
My database is a list of shopping carts that are connected to my product list by a foreign key, where there is the unit price of the item, for example, the cart is my shopping cart, product is the product list:
Then I can already export my data on my page.
But I want to calculate my total price below, the impression seems not very difficult, but can not remember, help, thank you, here is my code to extract data, and finally these 3 question marks are I want to get the total price:
function Checkitems ()
{
$result = mysql_query ("SELECT * from cart");
$num _rows = mysql_num_rows ($result);
if (! $num _rows)
{
Echo '
No product has been selected
';
}
Else
{
$sql = "Select Cart.cartid, Cart.productid,product.productname,product.productprice from the cart INNER JOIN product on cart. Productid=product.productid ORDER by Cart.cartid ";
$result = mysql_query ($sql);
Echo ("
Echo (" Cart idproduct namepriceremove Item");
while ($row = Mysql_fetch_array ($result)) {
{
$id = $row [' Cartid '];
$proid = $row [' ProductID '];
$proname = $row [' ProductName '];
$price = $row [' Productprice '];
Echo (" $id $proname$priceremove");
}
}
}
Echo ("");
echo " The total cost is $ ". $???;
}
Reply to discussion (solution)
$total = 0;
while ($row = Mysql_fetch_array ($result)) {
{
$id = $row [' Cartid '];
$proid = $row [' ProductID '];
$proname = $row [' ProductName '];
$price = $row [' Productprice '];
$total + = $price;
Thanks a lot! See this + = Just remembered to have learned last year, completely forget!!!