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

calculation of the total?

Quote Reply
calculation of the total?
sub { #Top 100 Links
my $tags = shift;
my $table = $DB->table('Links');
$table->select_options ('ORDER BY Hits DESC', 'LIMIT 100');
my $sth = $table->select;
my @output;
while (my $link = $sth->fetchrow_hashref) {
$tags->{totalhits} + = $link->{hits};
push (@output, $link);
}
return { top100_loop => \@output };
}

there is a column called hits, i try to calculate the total hit of selected links
but i get error. is there anything wrong


or if i could use calculation in tag? such as <%hits + $hits%>?
Quote Reply
Re: [austin99] calculation of the total? In reply to
Hi,

You need to pass it back to the template =)

Try:

Code:
return { top100_loop => \@output, total_hits => $tags->{totalhits}};

..and then call the total hits with : <%total_hits%>

..and change:

Code:
$tags->{totalhits} + = $link->{hits};

..to:

Code:
$tags->{totalhits} + = $link->{Hits};

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] calculation of the total? In reply to
Hi Andy.

thank you for your help


after having a try. i was given a error

syntax error at (eval 58) line 12, near "} return" Global symbol "@output" requires explicit package name at (eval 58) line 12. Global symbol "$tags" requires explicit package name at (eval 58) line 12


what does it mean?
Quote Reply
Re: [austin99] calculation of the total? In reply to
i got it

should be
Code:
$tags->{totalhits} += $link->{Hits};
Quote Reply
Re: [austin99] calculation of the total? In reply to
austin99 wrote:
i got it

should be
Code:
$tags->{totalhits} += $link->{Hits};

Oops yeah - just copied your code from before - didn't bother checking that bit for syntax =)

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