TecTao Posted February 8, 2008 Share Posted February 8, 2008 I'm familiar with the sum (pay_amount) as total in the Sql statement. but since I am joining about 4 tables and the 'pay_amount' is not in the first table, I was hoping there was a command that could total the numbers in the column rather then write a sql statement. the column $pay_amount is monthly amounts for a program. My select statement for a particular member produces a table of with each program and amount the member has signed up for. I need to get the sum of the $pay_amount column. I'm looking for a function that will sum that column and not do it through the sql statement. Thanks, m Quote Link to comment https://forums.phpfreaks.com/topic/90123-totaling-a-column-outside-sql-statement-repost/ Share on other sites More sharing options...
amites Posted February 8, 2008 Share Posted February 8, 2008 your post is difficult to follow, if I read it right a foreach loop would work $count = 0; foreach ($result as $row) { $count = $count + $row['pay_amount']; } good chance that's not what your looking for, might want to rethink the question, you'd be surprised how many times you come up with your own answer by thinking through the question, couldn't count the number of posts I've written only to come up with the answer to my own question half way through Quote Link to comment https://forums.phpfreaks.com/topic/90123-totaling-a-column-outside-sql-statement-repost/#findComment-462094 Share on other sites More sharing options...
TecTao Posted February 8, 2008 Author Share Posted February 8, 2008 Yes your write, it was a little confusing. I'm not looking for a total row count. I'm looking for a total of the variables without having to write the sum() as totals into the sql query since it is a join statement joining about 4 tables. for example the query statement returns 4 rows with the numbers 5,5,10,5 in the "pay_amount" column. Is there a function to total the variables so that the amount is obviously 25. I was thinking that maybe there was a function like the formatting function. Something outside of the sql statement. Thanks again m Quote Link to comment https://forums.phpfreaks.com/topic/90123-totaling-a-column-outside-sql-statement-repost/#findComment-462167 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.