Calculating shopping cart
Posted: Mon Jun 23, 2003 11:53 am
Hi,
I'm trying to calculate the total price in my shopping cart. When looping thru, the script must get the price from the database since only the id and quantity is stored in the session array. The first part that involves counting quantities works fine, but to get the price from the database, and multiply this by the products quantity, does not work som fine. I get an error on this line:
Heres the loop in the script:
I'm trying to calculate the total price in my shopping cart. When looping thru, the script must get the price from the database since only the id and quantity is stored in the session array. The first part that involves counting quantities works fine, but to get the price from the database, and multiply this by the products quantity, does not work som fine. I get an error on this line:
Code: Select all
$result = mysql_query( "SELECT * FROM products WHERE prodnr='".$key."'" );Code: Select all
foreach( $HTTP_SESSION_VARSї'items'] as $key=>$value )
{
//The quantity of products
$quantity = $number+$value;
$number = $quantity;
//The price of the products
$link = mysql_connect( $hostname, $username, $password );
mysql_select_db( $db )
or die ( "Couldn't open $db: ".mysql_error() );
$cart_total = 0
$result = mysql_query( "SELECT * FROM products WHERE prodnr='".$key."'" );
$row = mysql_fetch_assoc($result);
$cart_total = $cart_total + $rowї"price"] * $value;
}