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

User Page with Userlinks - top 5 hits and top rated

Quote Reply
User Page with Userlinks - top 5 hits and top rated
Hi
on my site most users have more than one entry.
What do you think?
Are there some globals possible to show on an individual userpage
the 5 links with the most hits
and the 5 top rated links
of a user?

I found this global to show the last 5 entries of a user

Code:
sub {
my $LinkOwner = shift;
my $sth;

my $link_db = $DB->table ('Links');
$link_db->select_options ('ORDER BY ID DESC', 'LIMIT 6');
if ($LinkOwner) {
$sth = $link_db->select( { isNew => "Yes", isValidated => "Yes", LinkOwner => $LinkOwner } );
} else {
$sth = $link_db->select( { isNew => "Yes", isValidated => "Yes" } );
}

my $output = '';

while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link', $link);
}
return $output;
}
Maybe this could changed to 5 top rated and 5 top hits??

Thanks
Matthias

Matthias
gpaed.de

Last edited by:

Matthias70: Aug 26, 2007, 4:05 AM
Quote Reply
Re: [Matthias70] User Page with Userlinks - top 5 hits and top rated In reply to
Hi,

Try this (took a while to get working, but think thats cos I was still a little tired - as its a bank hol monday here =))

Global name: users_listings

Code:
sub {

# normal links
my $link_db = $DB->table ('Links');
$link_db->select_options ('ORDER BY ID DESC') || die $GT::SQL::error;

my $sth = $link_db->select( { isValidated => "Yes", LinkOwner => $USER->{Username} } ) || die $GT::SQL::error;

my @links;

# just normal links.
while (my $link = $sth->fetchrow_hashref) {
push @links, $link;
}

# ratings
my $link_db = $DB->table ('Links');
$link_db->select_options ('ORDER BY Rating DESC', 'LIMIT 6') || die $GT::SQL::error;

my $sth = $link_db->select( { isValidated => "Yes", LinkOwner => $USER->{Username} } ) || die $GT::SQL::error;

my @links2;

# just top rated links.
while (my $link = $sth->fetchrow_hashref) {
push @links2, $link;
}

# ratings
my $link_db = $DB->table ('Links');
$link_db->select_options ('ORDER BY Hits DESC', 'LIMIT 6') || die $GT::SQL::error;

my $sth = $link_db->select( { isValidated => "Yes", LinkOwner => $USER->{Username} } ) || die $GT::SQL::error;

my @links3;

# just top rated links.
while (my $link = $sth->fetchrow_hashref) {
push @links3, $link;
}

return { user_links => \@links , user_links_by_hit => \@links3, user_links_by_rating => \@links2 }

}

Then, make a new template - and have this code in it:



Code:
<%users_listings%>

<h2>Your Listings</h2>

<%loop user_links%>
<%include link.html%>
<%endloop%>

<h2>Your Listings (by hits)</h2>

<%loop user_links_by_hit%>
<%include link.html%>
<%endloop%>

<h2>Your Listings (by rating)</h2>

<%loop user_links_by_rating%>
<%include link.html%>
<%endloop%>

Enjoy =)

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!

Last edited by:

Andy: Aug 27, 2007, 2:57 AM
Quote Reply
Re: [Andy] User Page with Userlinks - top 5 hits and top rated In reply to
Hi Andy,
I have an output, but the limits count does'nt work and on top of the page in the header there is
the output from this line

Code:
print "DOO";

Matthias

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] User Page with Userlinks - top 5 hits and top rated In reply to
Hi,

Quote:
the output from this line

Code:
print "DOO";

Whoops, I forgot to take that test line out =)

(the above global is fixed now)


Quote:
I have an output, but the limits count does'nt work and on top of the page in the header there is

Mmm.. an what "Limit" were you wanting? You can just update these bits, to list however many you want:

Code:
'LIMIT 6'

Hope that helps.

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] User Page with Userlinks - top 5 hits and top rated In reply to
Quote:
I have an output, but the limits count does'nt work and on top of the page in the header there is


Mmm.. an what "Limit" were you wanting? You can just update these bits, to list however many you want:

Code:
'LIMIT 6'
[/quote]
Hi Andy,
yes I know, that I can change the limit in the global, but it does'nt matter.
The global shows all entries of a user.

Matthias

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] User Page with Userlinks - top 5 hits and top rated In reply to
Hi,

Ah, I think what you want - is to edit:

Code:
$link_db->select_options ('ORDER BY ID DESC') || die $GT::SQL::error;

...to:

Code:
$link_db->select_options ('ORDER BY ID DESC','LIMIT 10') || die $GT::SQL::error;

(replace 10 with however many you want)

The other 2 selects should only grab 6 entries - so I'm guessing its the first loop (user_links) that is giving you all of their links.

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] User Page with Userlinks - top 5 hits and top rated In reply to
Hi Andy,
nearly perfect, the titles of the output
Code:
<%loop user_links%>
<%include link.html%>
<%endloop%>

have an url,
but
the titles of
Code:
<%loop user_links_by_hit%>
<%include link.html%>
<%endloop%>
and
Code:
<%loop user_links_by_rating%>
<%include link.html%>
<%endloop%>

have no urls in the title?

BTW: Is it possible just to show the hyperlinked titles of the entries without description.
Like this way
By hits
title1 - 100 hits
title2 - 67 his

By rating
title1 - Rating 9,5
title2 - Rating 8,5

Matthias

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] User Page with Userlinks - top 5 hits and top rated In reply to
Hi,

Try changing:

<%include link.html%>

..to:

Code:
<a href="<%config.db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Title%></a><br />

Hope that helps.

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] User Page with Userlinks - top 5 hits and top rated In reply to
Andy wrote:


<%include link.html%>

..to:

Code:
<a href="<%config.db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Title%></a><br />

That's it, very nice.
Is showing hits and ratings with the title to difficult?
Matthias

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] User Page with Userlinks - top 5 hits and top rated In reply to
Hi,

Try this:

Code:
<a href="<%config.db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Title%></a> (Hits: <%Hits%> Rating: <%Rating%>)<br />

Hope that helps.

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] User Page with Userlinks - top 5 hits and top rated In reply to
Hi Andy,
just perfect Cool
Thanks
Matthias

Matthias
gpaed.de