Gossamer Forum
Quote Reply
Custom random link
Hi

I have a global that is supposed to return a random link from the links with flag (isSponsored = Yes)

sub {
my $db = $DB->table('Links');
my $total = $db->count ( 'isValidated' => 'Yes');
my $rand = int( rand($total) );
my $cond = GT::SQL::Condition->new('isSponsored', '=', 'Yes');
$db->select_options ("LIMIT $rand, 1");
my $link = $db->select->fetchrow_hashref;
return Links::SiteHTML::display('link', $link);
}

The gloabl is returing links regardless of my condition (all over the database)

Any suggsetions?
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Custom random link In reply to
You need select($cond) instead of select.
Quote Reply
Re: [katabd] Custom random link In reply to
The final code was:

sub {
my $db = $DB->table('Links');
my $cond = GT::SQL::Condition->new('isSponsored', '=', 'Yes');
my $total = $db->count ( $cond );
my $rand = int rand $total;
$db->select_options ("LIMIT $rand, 1");
my $link = $db->select($cond)->fetchrow_hashref;

if (length $link->{Title} > 20) {
$link->{Title} = substr($link->{Title}, 0, 20) . '...';
}
return Links::SiteHTML::display('link', $link);
}
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory