Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Top 5 of category

Quote Reply
Top 5 of category
Hello,

I saw a post at: http://www.gossamer-threads.com/...um9/HTML/000184.html

I need directions if any could help on how to implement this into my LinksSQL.

Please help. Thanks.

Quote Reply
Re: Top 5 of category In reply to
I posted a top-nn for the search.cgi a month back. The same principle can be used for creating a top anything. I've also put the top keywords onto my home page, but could do that with links, or anything else:

http://www.postcards.com/DigitalPostcards/pages/

It's not ssi based, so it only changes when the page is re-built. The search terms (and you could put top links, top hits, and top keywords) on the search page, is built every time search.cgi is run.

When HTML_Templates is called, it puts the values into a variable, that can be included on any page, or in any cgi that uses HTML_Templates.pm.


Quote Reply
Re: Top 5 of category In reply to
Hello Pugdog,

I found your post add was curious if you could re-write the sub for me so that I could show the top5 links by hits.

Here is your sub:
Code:
sub top5 {
# -----------------------------------------------
# Returns a list of the top5 searched terms.
#
my $in = new CGI;
my $search = new Links::DBSQL $LINKS{admin_root_path} . "/defs/Search_Log.def";
# Let's get a list of the top 5 terms ordered by number of times someone
# has searched on them.
my $results = $search->query ( { Term => '*', sb => 'Count', so => 'DESC', mh => 5 } );
my $output = '';
my $term_q;
if ($search->hits) {
foreach my $term (@{$results}) {
$term = $search->array_to_hash($term);
$term_q = $in->escape($term->{Term});
$output .= qq~ <LI><a href="$LINKS{db_cgi_url}/search.cgi?query=$term_q">${$term}{Term}</a>
~;
}
}
else {
$output = "Sorry no one has searched for anything yet.";
}
return $output;
}
I would be very grateful.

Quote Reply
Re: Top 5 of category In reply to
Did you try the codes that Widgetz posted on October 27,1999???

Regards,

Eliot Lee
Quote Reply
Re: Top 5 of category In reply to
Hello,

I've been trying but I can't figure out where to place his code in nph-build.cgi cause the instructions are not specific enough.

Can you help?

Quote Reply
Re: Top 5 of category In reply to
Have you tried putting those codes AFTER the following codes:

Code:

$total_links = $numlinks;


in the sub build_category_pages

Regards,

Eliot Lee
Quote Reply
Re: Top 5 of category In reply to
I added this in sub build_category_pages

after $total_links = $numlinks;

my ($top5subs, $top5);
my $top5cat = 1;
$sth = $LINKDB->prepare ( " SELECT SubCategoryID FROM CategoryHeiarchy WHERE CategoryID = ? ");
$sth->execute($top5cat) or die $DBI::errstr;
while (my $cat = ($sth->fetchrow_array)[0]) {
$top5subs .= " OR CategoryID = $cat";
}
$sth = $LINKDB->prepare ( " SELECT * FROM Links WHERE CategoryID = ? $top5subs ORDER BY Hits DESC LIMIT 5 ");
$sth->execute($top5cat) or die $DBI::errstr;
while (my $link = $sth->fetchrow_hashref) {
$top5 .= "${$link}{'Title'} | ${$link}{'Hits'} Hits
\n";
}


And I got this error when I ran the perl debugger in telnet:
Global symbol "$sth" requires explicit package name at nph-build.cgi line 430.

Quote Reply
Re: Top 5 of category In reply to
When doing mods, check the similar code. You know you'll have to do a

select * from Links order Hits DESC Limit 5 (or something like that).

Where do we do that? Check the Ratings/review and/or popular links areas. Then switch that sort of code in for the 'query' on the search.

It's a matter of looking for the right framework (output type) then inserting the code you want in the middle of it. Not quite as bad as the old windows joke -- "How many windows programs have been written? One. And it's just been modified"

I'll have to look at it a bit to do it, and I've learned not to code when I can barely see the screen... too many typos that end up having to be fixed.



Quote Reply
Re: Top 5 of category In reply to
Ok I had to add $sth to the My statement at the top of the sub.

Now It builds the site...how do I set it up to call the top 5. I added <%top5%> to my home.html template...but it said "Unknown Tag"

Sorry if these questions seem very newbie to you pros. I appreciate your help.