major insult Posted January 3, 2008 Share Posted January 3, 2008 I am trying to add rows together i have it adding but i only want the answer. when i try to add 6500+150 it shows 6500 then 6650. i only want 6650 Quote Link to comment https://forums.phpfreaks.com/topic/84379-adding-rows/ Share on other sites More sharing options...
frost Posted January 3, 2008 Share Posted January 3, 2008 can you paste your code here? Quote Link to comment https://forums.phpfreaks.com/topic/84379-adding-rows/#findComment-429756 Share on other sites More sharing options...
major insult Posted January 3, 2008 Author Share Posted January 3, 2008 while ($row = mysql_fetch_assoc($result)) { $total += $row['amount']; echo"$total"; Quote Link to comment https://forums.phpfreaks.com/topic/84379-adding-rows/#findComment-429757 Share on other sites More sharing options...
frost Posted January 3, 2008 Share Posted January 3, 2008 Try: $total = $total + $row['amount']; echo"$total"; Quote Link to comment https://forums.phpfreaks.com/topic/84379-adding-rows/#findComment-429758 Share on other sites More sharing options...
major insult Posted January 3, 2008 Author Share Posted January 3, 2008 still shows the math Quote Link to comment https://forums.phpfreaks.com/topic/84379-adding-rows/#findComment-429763 Share on other sites More sharing options...
frost Posted January 3, 2008 Share Posted January 3, 2008 Well this: <? $total = 10; $row['amount'] = 5; $total = $total + $row['amount']; echo"$total"; ?> Spits out 15. Are you sure you removed the = sign? Quote Link to comment https://forums.phpfreaks.com/topic/84379-adding-rows/#findComment-429767 Share on other sites More sharing options...
duclet Posted January 3, 2008 Share Posted January 3, 2008 Move your echo out of the while loop. Quote Link to comment https://forums.phpfreaks.com/topic/84379-adding-rows/#findComment-429769 Share on other sites More sharing options...
PFMaBiSmAd Posted January 3, 2008 Share Posted January 3, 2008 Edit: darn, too slow on the Post button... same answer as above ^^^ Umm. He is using php code to total up values, but only wants to echo the final total. The answer is simple, put the echo $total; statement after the end of your while() loop. Quote Link to comment https://forums.phpfreaks.com/topic/84379-adding-rows/#findComment-429772 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.