gum1982 Posted February 1, 2010 Share Posted February 1, 2010 Hello can someone please help me im running a foreach loop that is pulling the prices value out off my database as follows. this is the function function one_life() { db_connect(); $query = "SELECT * FROM paypal_payment_info order by paypal_payment_info.mc_gross DESC"; $result = mysql_query($query); if(!$result) { echo mysql_error(); } $result = db_result_to_array($result); return $result; } $one_lifes = one_life(); This is my foreach loop <?php foreach($one_lifes as $one_life) { ?> <?php echo $one_life['mc_gross']; ?> <?php } ?> So this gives me the values i have a list like this. 200 10 30 200 350 What i need to do is add all these values together and echo one overall amount which would be say 790 for the example. Any Help Please? Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 1, 2010 Share Posted February 1, 2010 <?php $total = 0; foreach($one_lifes as $one_life) { echo $one_life['mc_gross']; $total += $one_life['mc_gross']; } echo 'Total: '.$total; ?> Quote Link to comment Share on other sites More sharing options...
gum1982 Posted February 1, 2010 Author Share Posted February 1, 2010 Legend 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.