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

Global for Last Searched Keywords??

Quote Reply
Global for Last Searched Keywords??
Is there a working global available for the last (5 or 10) keywords searched for on an LSQL site?



Thanks.



Mark
Quote Reply
Re: [mgeyman] Global for Last Searched Keywords?? In reply to
Is this in the wrong forum, or do you want a global that works on Gossamer Forum to pull last searches on a Links SQL install?

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Global for Last Searched Keywords?? In reply to
Alex,



Sorry this was posted in the wrong forum. Yes, I am looking for a global that pulls the last searched keywords. Is there one that exists. I also have the Keywords plugin.



Thanks a lot.



mgeyman
Quote Reply
Re: [mgeyman] Global for Last Searched Keywords?? In reply to
Try

sub {
my ($output,$db,$sth);
my $db = $DB->table('SearchLog');
$db->select_options ('ORDER BY TS DESC', 'LIMIT 5');
$sth = $db->select;

while (my $row = $sth->fetchrow_hashref) {
$output .= qq~<a href="$CFG->{db_cgi_url}/search.cgi?query=$row->{Term}">$row->{Term}</a>&nbsp;-&nbsp;~;
}
return $output > -1 ? join('-', $output): 'No terms yet!';

}
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Global for Last Searched Keywords?? In reply to
katabd,

Hmmm. I tried adding it and this is the result I get:

A fatal error has occured:
Can't call method "fetchrow_hashref" on an undefined value at (eval 17) line 7.


Please enable debugging in setup for more details.Stack Trace======================================Links (6178): Links::environment called at /home/ohiobiz/linkssql2/admin/Links.pm line 418 with no arguments.Links (6178): Links::fatal called at (eval 17) line 7 with arguments (Can't call method "fetchrow_hashref" on an undefined value at (eval 17) line 7. ).Links (6178): Links::__ANON__ called at /home/ohiobiz/linkssql2/admin/GT/Template.pm line 759 with arguments (HASH(0x84c6050)).Links (6178): GT::Template::_get_var called at /home/ohiobiz/linkssql2/admin/templates/default/compiled/rate.html.compiled line 70 with arguments (GT::Template=HASH(0x84c5f18), last_searched, 0, 1).Links (6178): GT::Template::__ANON__ called at /home/ohiobiz/linkssql2/admin/GT/Template.pm line 539 with arguments (GT::Template=HASH(0x84c5f18)).Links (6178): GT::Template::_parse called at /home/ohiobiz/linkssql2/admin/GT/Template.pm line 89 with arguments (GT::Template=HASH(0x84c5f18), rate.html, HASH(0x84c52d8)).Links (6178): GT::Template::parse called at /home/ohiobiz/linkssql2/admin/Links.pm line 291 with arguments (GT::Template, rate.html, ARRAY(0x84c5308), HASH(0x84c52d8)).Links (6178): Links::user_page called at (eval 10) line 1 with arguments (rate.html, HASH(0x84c188c), HASH(0x84c52d8)).Links (6178): Links::SiteHTML::site_html_rate called at /home/ohiobiz/linkssql2/admin/GT/Plugins.pm line 88 with arguments (HASH(0x84c188c), [undef]).Links (6178): GT::Plugins::dispatch called at /home/ohiobiz/linkssql2/admin/Links/SiteHTML.pm line 28 with arguments (GT::Plugins, /home/ohiobiz/linkssql2/admin/Plugins, site_html_rate, *Links::SiteHTML::site_html_rate, HASH(0x84c188c), [undef]).Links (6178): Links::SiteHTML::display called at /home/ohiobiz/linkssql2/admin/Links/User/Rate.pm line 48 with arguments (rate, HASH(0x84c188c)).Links (6178): Links::User::Rate::handle called at /home/ohiobiz/linkssql2/admin/GT/Plugins.pm line 88 with no arguments.Links (6178): GT::Plugins::dispatch called at /home/www/pages/ohiobiz/linkssql2/rate.cgi line 25 with arguments (GT::Plugins, /home/ohiobiz/linkssql2/admin/Plugins, handle_rate, CODE(0x80d49fc)).How can I modify the global to get this to work properly?Thanks.mgeyman
Quote Reply
Re: [mgeyman] Global for Last Searched Keywords?? In reply to
Replace

while (my $row = $sth->fetchrow_hashref) {

with


while ($sth and my $row = $sth->fetchrow_hashref) {

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Global for Last Searched Keywords?? In reply to
Hmm he shouldn't have to do that.
Quote Reply
Re: [Paul] Global for Last Searched Keywords?? In reply to
This is actually something that confuses me time and again:

my $sth = $table->select;
my $row = $sth->fetchrow_hashref;

It seems to produce an error if the select method did not return anything. But then again, in some situations it works....

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Global for Last Searched Keywords?? In reply to
I think that must mean the query failed.

So before the while loop I think you'll need to add:

my $sth = $db->select or die $GT::SQL::error;
Quote Reply
Re: [yogi] Global for Last Searched Keywords?? In reply to
I think what is happening is an undefined is being returned, rather than a value, and yes, it seems quirky, in that in some situations it works, in others it doesn't, and you have to find some work arounds. Pretty much doing what paul suggests, checking for errors, and checking values before you try to use them, is the only reliable way to make sure any method works in all situations.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [yogi] Global for Last Searched Keywords?? In reply to
yogi,

I made your modification. It took away the error message but no results see to appear on the page.

mgeyman
Quote Reply
Re: [Paul] Global for Last Searched Keywords?? In reply to
Paul,

I also added this line of code and when I bring up the page it just hangs, it doesn't pull up anything - I have to close out of my browser.

mgeyman
Quote Reply
Re: [mgeyman] Global for Last Searched Keywords?? In reply to
That code wouldn't/shouldn't make your browser hang, all it does it kill the script if no statement handle is returned. Maybe it was a freak thing or did it happen every time?

Last edited by:

Paul: Aug 25, 2002, 8:00 AM