Jump to content

Totaling a column outside SQL statement (repost)


TecTao

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.