Jump to content

Adding the contents of a Select Query.


allydm

Recommended Posts

Hi there.

I have a select query

[code]
$total_query = "SELECT `product_price` FROM `robin_basket` WHERE session_id = '".session_id()."'";
$total_result = mysql_query($total_query);
$total = mysql_fetch_assoc($total_result);
[/code]

Now this query returns 3 results (as it should). However i need to add those three results together, and i'm not sure how to do this.

The results are:
105
105
105
So the total of them all should be 315.

I have attempted to solve this problem, by using the following code:

[code]
do {
$total_minus_shipping = array_sum($total);
}
while ($total = mysql_fetch_array($total_result));
[/code]

However, this only adds two results (giving me a total of 210) and not all three added together (which would result in 315).

If someone could explain to me how to get the results to add up correctly i'd be greatful.

Allydm.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.