PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Zeceer
Forum Contributor
Posts: 136 Joined: Fri Aug 02, 2002 5:10 am
Location: Norway
Post
by Zeceer » 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:
Code: Select all
$result = mysql_query( "SELECT * FROM products WHERE prodnr='".$key."'" );
Heres the loop in the script:
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;
}
m@ndio
Forum Regular
Posts: 163 Joined: Fri Jun 06, 2003 12:09 pm
Location: UK
Post
by m@ndio » Mon Jun 23, 2003 11:56 am
What error do you get?
Zeceer
Forum Contributor
Posts: 136 Joined: Fri Aug 02, 2002 5:10 am
Location: Norway
Post
by Zeceer » Mon Jun 23, 2003 12:07 pm
Here you go mate
Parse error: parse error, unexpected T_VARIABLE in E:\Web Server\inc shop v2.0\cart_summary.php on line 31
Stoker
Forum Regular
Posts: 782 Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:
Post
by Stoker » Mon Jun 23, 2003 12:08 pm
A missing semicolon on the line before...
$cart_total = 0 ;
m@ndio
Forum Regular
Posts: 163 Joined: Fri Jun 06, 2003 12:09 pm
Location: UK
Post
by m@ndio » Mon Jun 23, 2003 12:09 pm
yea, hehe DOH! I hate those ones...
Zeceer
Forum Contributor
Posts: 136 Joined: Fri Aug 02, 2002 5:10 am
Location: Norway
Post
by Zeceer » Mon Jun 23, 2003 12:17 pm
There! Ahhh, it works
. I have a tendence to overlook those small errors in the coding after coding a while
Stoker
Forum Regular
Posts: 782 Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:
Post
by Stoker » Mon Jun 23, 2003 1:20 pm
Kven kveit sa mannen :p