Gossamer Forum
Quote Reply
Limit Links help
Heya all,

This has been frustrating me all morning... I'm trying to grab the X most recent links (wow, like that's never been done before!) but want to pass the number of links to return from the template. I have:

Code:
sub {
my ($output,$sth,$link);
my $limit = shift;
my $search_db = $DB->table('Links');
$search_db->select_options ("ORDER BY Add_Date DESC","LIMIT $limit");
$sth = $search_db->select ( { isValidated => 'Yes' });
while ($link = $sth->fetchrow_hashref) {
if (length $link->{Title} > 50) {
$link->{Title} = substr($link->{Title}, 0, 50) . '...';
}
$output .= Links::SiteHTML::display ('link_new_list', $link);
}
return $output;
}

I call it with: <%globalname('X')%> and I get: Can't call method "fetchrow_hashref" on an undefined value at (eval 1012) line 7.

If I hard-code $limit in the global it works fine. What am I missing?

Safe swoops
Sangiro

Last edited by:

sangiro: Jul 24, 2006, 4:00 AM
Quote Reply
Re: [sangiro] Limit Links help In reply to
Check that $limit in fact does contain the right value (ie. print it to check).

Adrian
Quote Reply
Re: [brewt] Limit Links help In reply to
Hey Adrian,

I switched the first 2 lines in the global around and now it works fine. Crazy

Code:
sub {
my $limit = shift;
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ("ORDER BY Add_Date DESC","LIMIT $limit");
$sth = $search_db->select ( { isValidated => 'Yes' });
while ($link = $sth->fetchrow_hashref) {
if (length $link->{Title} > 50) {
$link->{Title} = substr($link->{Title}, 0, 50) . '...';
}
$output .= Links::SiteHTML::display ('link_new_list', $link);
}
return $output;
}

Safe swoops
Sangiro