Gossamer Forum
Quote Reply
SELECT SUM() - help
hello!

I'm processing a loop of records and want to get the total sum of a particular column for all of the records.

I want the total to be allocated to $total_asked.

The column I'm after is "asked".

The following code isn't working for me... where it should return a total of 75 the result I'm getting is 556538336.

Code:
for each of my records...

my $cond = GT::SQL::Condition->new(
question_id_fk => '=' => "$_->{'question_id'}"
);

$total_asked += $db->select('SUM(asked)', $cond );

...

Can anyone help?

Thanks

r


edit: just corrected the code

Last edited by:

ryel01: Aug 20, 2004, 1:27 AM
Quote Reply
Re: [ryel01] SELECT SUM() - help In reply to
figured it out... in case anyone has the same question...

Code:
for each of my records...

my $cond = GT::SQL::Condition->new(
question_id_fk => '=' => "$_->{'question_id'}"
);

$total_asked += $db->select('SUM(asked)', $cond )->fetchrow_array ;
...

r
Quote Reply
Re: [ryel01] SELECT SUM() - help In reply to
Sorry, bit late posting.

You should be able to use just "fetchrow", instead of "fetchrow_array" (just makes it that little shorted, and easier to read).

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] SELECT SUM() - help In reply to
ah cool - thanks for that.

"almost" finished my little project... will have a plugin to show you soon. Cool

r