Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

A global to calculate the average of 6 link fields ( integer )

Quote Reply
A global to calculate the average of 6 link fields ( integer )
I have 6 fields all on Links DB

they are all integers ranging from 5,5.5,6,6.5,7,7.5,8,8.5,9,9.5,10 ( essentially a rating system )

I need to calculate an average Overall rating.

( field1 + field2 + field3 + field4 + field5 + field6 )/6=overallrating

Something like that... Can someone show me a global to do this ?

Thanks in advance!
Quote Reply
Re: [Stephan99] A global to calculate the average of 6 link fields ( integer ) In reply to
first, 5.5, 6.5, etc are *not* Integers, they are reals or floats

sub {
my $ID = shift;
my $db = $DB->table('Links');
my $sth = $db->get($ID);
my $rec = $sth->fetchrow_hashref;
my $total = $rec->{'field_1'} + $rec->{'field_2'} etc for however many fields you have;
$total = $total / 6 ; # if you have 6 fields
return $total;
}


You'd call it with <%rate_average LinkID%> or <%rate_average ID%> depending on where you are

Should work, but you need to edit it a little.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.