Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

Total of a Field...

Quote Reply
Total of a Field...
I added a new field to the users table called "user_stores". This field will contain different values for each user. I am trying to write a global that will add up all of the values in this field for an overall total. Any help would be greatly appreciated.

Sean
Quote Reply
Re: [SeanP] Total of a Field... In reply to
For every user?

You could try;

<%global_name%>

Code:
sub {
my $total;
my $sth = $DB->table('User')->select( ['FieldName'] );
while (my ($value) = $sth->fetchrow) {
$total += $value;
}
return $total;
}

This is untested, and will require a little tweaking to match up with your field names ... but it should work :)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Total of a Field... In reply to
That works great! Thanks Andy!