Simple but silly :-) - Please Help :-)

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

Post Reply
netties001
Forum Newbie
Posts: 4
Joined: Thu Jun 04, 2009 5:16 pm

Simple but silly :-) - Please Help :-)

Post by netties001 »

Hi, i'm new to this site and pretty new to PHP and I have a really simple but silly question for everyone.

Basically, at the moment I'm trying to return the total sum of a price column from a database I have. I've built my own shopping cart as a side project and would like to know how to add the total values of the cart for that user together.

Here's what I have so far...

Code: Select all

$query2="SELECT * FROM orders_temp WHERE order_username = '" . $_SESSION["user_name"] . "'";
$result2=mysql_query($query2);
 
while($r1=mysql_fetch_array($result2))
    {
        $order_product_price=$r1["order_product_price"];
 
}
How do I add the result of all the prices together to get a total cost for the user?

Sorry, probably seems a simple thing but I've looked all over google and it might as well be in spanish to me lol :-)

Thanks in Advance.
Netties :drunk:
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Simple but silly :-) - Please Help :-)

Post by Darhazer »

Code: Select all

$total = 0;
while($r1=mysql_fetch_array($result2))
{
$total += $r1["order_product_price"];
}
netties001
Forum Newbie
Posts: 4
Joined: Thu Jun 04, 2009 5:16 pm

Re: Simple but silly :-) - Please Help :-)

Post by netties001 »

You're a star cheers! :-)

The value isn't showing anything after the decimel point, i.e. £10.00 is showing as £10 ? - any advice?

Thanks,
Netties.
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: Simple but silly :-) - Please Help :-)

Post by mikemike »

See number_format() - that'll sort it for you.
netties001
Forum Newbie
Posts: 4
Joined: Thu Jun 04, 2009 5:16 pm

Re: Simple but silly :-) - Please Help :-)

Post by netties001 »

Thanks for the help, it totally solved it - cheers ;-) much appreciated.
Post Reply