guymclaren Posted June 22, 2011 Share Posted June 22, 2011 Before anyone has a go at me, I have Googled, tried to create an array from the result and have failed miserably. In essence what I have is a result from a sql query multiplied with another giving me a row total. while row exists $var = $result1 * $result2 Now I want to total up $var1 which could be a single entry or a list of entries. I have tried to create an array for($i = 0; $i < count($var); $i++){ echo $var[$i].","; } Get no result, except , $val1 = array($var[$i]); echo $val1; No result PLease help, my brain is not co-operating today. Quote Link to comment https://forums.phpfreaks.com/topic/240092-creating-a-sum-from-a-variable-result/ Share on other sites More sharing options...
AMcHarg Posted June 22, 2011 Share Posted June 22, 2011 Don't see why you need an array. Why not just have another variable in the while loop that totals up $var each time it loops? Like... $sum_of_var = $sum_of_var+$var; Or am I misunderstanding? Quote Link to comment https://forums.phpfreaks.com/topic/240092-creating-a-sum-from-a-variable-result/#findComment-1233258 Share on other sites More sharing options...
guymclaren Posted June 22, 2011 Author Share Posted June 22, 2011 so simple and elegant, Thank you. I'll try that Quote Link to comment https://forums.phpfreaks.com/topic/240092-creating-a-sum-from-a-variable-result/#findComment-1233263 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.