The price of a column of products in the database is summed up to get the total price of a website to be purchased this semester. most of the websites are completed, with only the total price being calculated.
My database is a shopping cart list that is connected to my product list through the foreign key, where there is the unit price of the product, for example, cart is my shopping cart, and product is the product list:
Then I can export my data on my page.
However, I want to calculate my total price below. it seems that it is not very difficult, but I cannot remember it at all. for help, thank you. below is my data extraction code, the last three question marks are the total price I want:
Function checkItems ()
{
$ Result = mysql_query ("SELECT * FROM cart ");
$ Num_rows = mysql_num_rows ($ result );
If (! $ Num_rows)
{
Echo'
No product have been selected
';
}
Else
{
$ SQL = "SELECT cart. cartID, cart. productID, product. productName, product. productPrice FROM 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 ['produtid'];
$ 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 ['produtid'];
$ Proname = $ row ['productname '];
$ Price = $ row ['productprice'];
$ Total + = $ price;
Thank you! When I saw this + =, I remembered learning it last year. I forgot it !!!