Gossamer Forum
Quote Reply
Global Tag
Hi-

I'm trying to create a Global Tag that would allow me to show users the total numer of hits they have for all of their links. I currently use the following global to show the total number of hits for my site:

total_hits =>

sub { my ($total) = $DB->table('Links')->select(['SUM(Hits)'])->fetchrow_array; return $total;}

I can't seem to modify this correctly for a new global tag called total_user_hits to get it to show the total number of hits for a specific user that is logged in. Basically, I just want it to show the SUM(Hits) WHERE Username='---Currently Logged in Username--'. Does anyone know the proper syntax to do this in a global? It would be much appreciated!

-FrankM
Quote Reply
Re: [FrankM] Global Tag In reply to
sub { my ($total) = $DB->table('Links')->select({'Linkowner => $Linkowner'}, ['SUM(Hits)'])->fetchrow_array; return $total;}

This assumes you know how to get $LinkOwner or whatever the var is
Quote Reply
Re: [,] Global Tag In reply to
Thanks for the reply. Somehow, I couldn't get this to work. Do you know how I would get the $LinkOwner var? I would only be using this global tag on template pages when the user is logged in.

-FrankM
Quote Reply
Re: [FrankM] Global Tag In reply to
maybe via $USER->$LinkOwner?
Quote Reply
Re: [,] Global Tag In reply to
Thanks again...

I tried that and various other combinations, but I couldn't get it to work. It's probably something really simple, but I just can't seem to get it to work...Frown

-Frank M.
Quote Reply
Re: [FrankM] Global Tag In reply to
Try:

Code:
sub {
return $DB->table('Links')->select( { LinkOwner => $_[0] }, 'SUM(Hits)' )->fetchrow
}

In your template you'd use:

<%MyGlobal(Username)%>

...where Username is the tag used to display the username of the logged in user.
Quote Reply
Re: [Paul] Global Tag In reply to
Thanks very much for your help. I tried the code you provided for the global which I named: user_hits. But when I put the tag: <%user_hits%> on a page it doesn't return any value for the total number of hits. (It does show a proper value for the tag: <%Username%>, though). I wonder what the problem might be? When I log in under the username, the user definitely has a number of validated links that have Hits recorded for them.Crazy

-FrankM
Quote Reply
Re: [FrankM] Global Tag In reply to
Try:

<%user_hits($Username)%>
Quote Reply
Re: [Paul] Global Tag In reply to
Thanks very much! That worked great. Smile I should have followed your instructions more closely the first time.

-FrankM
Quote Reply
Re: [Paul] Global Tag In reply to
You're getting pretty quick with those one-liners ;)


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Global Tag In reply to
>>
You're getting pretty quick with those one-liners ;)
<<

They are fun :)