Gossamer Forum
Quote Reply
Fetch a link
Hi,

I want to get the latest link in a specifc category and tried calling the below global as:

<%fetch('1998')%> (where 1988 is the Category number I want the Top link from)

The global I use:

Code:
sub {
my $tags = shift;
my $table = $DB->table('Links');
$table->select_options ('ORDER BY Add_Time DESC', 'LIMIT 1');
return { article_loop => $table->select ( {CategoryID => $tags->{ID}, isValidated => "Yes"} )->fetchall_hashref };
}

But I get an error all the time...

Error: Can't use string ("1988") as a HASH ref while "strict refs" in use at (eval 32) line 3.


Any suggestions?

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Fetch a link In reply to
Because you are passing in 1998 which is a string but you are trying to call $tags->{ID}.

my $tags = shift;

...is assigning 1998 to $tags
Quote Reply
Re: [Paul] Fetch a link In reply to
Yes but I do want to set $tags to the category right?

What should I do?

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Fetch a link In reply to
Yes but what I mean is that when you pass in 1998 and then use:

my $tags = shift;

...you simply have $tags which has a value of 1998. You are trying to use $tags as a hashref by calling:

$tags->{ID}

....perl throws the error because $tags is not a hashref, it is an ordinary scalar, so in your select when you use:

CategoryID => $tags->{ID}

...it should just be:

CategoryID => $tags

Last edited by:

Paul: Mar 22, 2003, 1:36 AM
Quote Reply
Re: [Paul] Fetch a link In reply to
I treid that - but still get an error::

Error: Can't call method "fetchall_hashref" on an undefined value at (eval 31) line 5.

Should I not call it as <%fetch('1988')%> ? dounble quotes or..

Any ideas?

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Fetch a link In reply to
Got it...

Forgot to use:

$DB->table('Links','CatLinks');


Thanks again

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Fetch a link In reply to
Hi, Klausovgreen;

I've tried to get this running...

What was your final calling convention and code?

Thanks!
Quote Reply
Re: [webslicer] Fetch a link In reply to
Hi,

My global ended up looking like:

Code:
sub {
my $tags = shift;
my $table = $DB->table('Links','CatLinks');
$table->select_options ('ORDER BY Add_Date DESC', 'LIMIT 1');
return { article_loop => $table->select ( {CategoryID => $tags, isValidated => "Yes"} )->fetchall_hashref };
}


and you call it as:

Code:
<%fetch_link('1986')%>
<%loop article_loop%>
<%Title%>
<%endloop%>

Where '1986' is the ID of the category you want to receive the latest link from
Klaus

http://www.ameinfo.com

Last edited by:

klauslovgreen: Mar 24, 2003, 3:12 AM