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

Top ten daily searches...

Quote Reply
Top ten daily searches...
This is based off some code Paul posted a while back. I'm trying to pull a top list from a set of daily searches using the Improved Search Logger plugin. Can someone tell me what I'm doing wrong? I keep getting the error:

Can't call method "fetchrow_hashref" on an undefined value at (eval 369) line 16.

Code:
sub {
# -----------------------------------------------
# Returns a list of the daily Top 10 Searched terms.

# Gets the current date.
Links::init_date();
GT::Date::date_set_format($CFG->{'date_db_format'});
my $date = GT::Date::date_get();

my (@output,$db,$sth);

$db = $DB->table('SearchLogDaily');
$db->select_options ('ORDER BY HitCount DESC', 'WHERE Hit_Date = \"$date\"', 'LIMIT 10');
$sth = $db->select;

while (my $row = $sth->fetchrow_hashref) {
push @output, qq~<a href="$CFG->{db_cgi_url}/search.cgi?query=$row->{Term}">$row->{Term}</a>~;
}

return $#output > -1 ? join('<br>', @output) : 'No terms yet!';

}

Thanks upfront...

Sean
Quote Reply
Re: [SeanP] Top ten daily searches... In reply to
Turn on debugging and check your error log.

Are you sure the WHERE clause should be inside select_options?.....I think you should remove that and use:

$sth = $db->select( { Hit_Date => $date } );
Quote Reply
Re: [Paul] Top ten daily searches... In reply to
You're right. Thanks, that worked great!

I have another global that gives me a total daily search count. Can you tell me how do I do the same in it?

Code:
sub {

# Gets the current date.
Links::init_date();
GT::Date::date_set_format($CFG->{'date_db_format'});
my $date = GT::Date::date_get();

my ($total) = $DB->table('SearchLogDaily')->select(['SUM(HitCount)'])->fetchrow_array;

if ($total < 1){
$total = '0';
}

return $total;
}

Sean
Quote Reply
Re: [SeanP] Top ten daily searches... In reply to
The same what?
Quote Reply
Re: [Paul] Top ten daily searches... In reply to
Sorry... I'm trying to add the where Hit_Date = $date clause to the select line:

Code:
my ($total) = $DB->table('SearchLogDaily')->select(['SUM(HitCount)'])->fetchrow_array;

Sean
Quote Reply
Re: [SeanP] Top ten daily searches... In reply to
Code:
my $total = $DB->table('SearchLogDaily')->select( { Hit_Date => $date }, 'SUM(HitCount)' )->fetchrow;

Last edited by:

Paul: Sep 26, 2002, 2:01 PM
Quote Reply
Re: [Paul] Top ten daily searches... In reply to
Excellent! Works great. Thanks for the help...

Sean