Page 1 of 1

Calculating shopping cart

Posted: Mon Jun 23, 2003 11:53 am
by Zeceer
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;
    }

Posted: Mon Jun 23, 2003 11:56 am
by m@ndio
What error do you get?

Posted: Mon Jun 23, 2003 12:07 pm
by Zeceer
Here you go mate :D
Parse error: parse error, unexpected T_VARIABLE in E:\Web Server\inc shop v2.0\cart_summary.php on line 31

Posted: Mon Jun 23, 2003 12:08 pm
by Stoker
A missing semicolon on the line before...

$cart_total = 0 ;

Posted: Mon Jun 23, 2003 12:09 pm
by m@ndio
yea, hehe DOH! I hate those ones...

Posted: Mon Jun 23, 2003 12:17 pm
by Zeceer
There! Ahhh, it works :D. I have a tendence to overlook those small errors in the coding after coding a while :oops:

Posted: Mon Jun 23, 2003 1:20 pm
by Stoker
Kven kveit sa mannen :p