allydm Posted September 4, 2006 Share Posted September 4, 2006 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:105105105So 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 4, 2006 Share Posted September 4, 2006 If all you want is the total[code]$total_query = "SELECT SUM(`product_price`) FROM `robin_basket` WHERE session_id = '".session_id()."'";$total_result = mysql_query($total_query);$total = mysql_result($total_result, 0, 0);[/code] Quote Link to comment Share on other sites More sharing options...
allydm Posted September 4, 2006 Author Share Posted September 4, 2006 Thankyou!Works like a charm. Think i'll go check out all the mysql functions now see if there are any more gems to make the coding easier.Thanks again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.