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

Products: Gossamer Links: Development, Plugins and Globals: Re: [afinlr] Random Global Questions: Edit Log

Here is the list of edits for this post
Re: [afinlr] Random Global Questions
Thanks. It works.

But I think there might be some extra code in the Global, because the way it was set up originally, it limited the number of links it showed already. It seems to be ignoring the first limit.

Here is the global that is a mix of what you shared with me and from pervious attempts. The items in bold are the two times I believe the limits are set (and they are set differently) The global outputs 5 right now, the way it is written below:

sub {
my $tags = shift;
my $link_db = $DB->table('Links','CatLinks');
my $cat_id = $tags->{Random_CatID};
my $limit = $tags->{Random_Limit} || 3;
my (@output, $sth);
$link_db->select_options ('ORDER BY RAND()', "LIMIT $limit");
if ($cat_id) {
$sth = $link_db->select ( { CategoryID => $cat_id });
}
else {
$sth = $link_db->select;
}
while (my $hash = $sth->fetchrow_hashref) {
push @output, $hash;
}
my $cat_db = $DB->table('Category');
my $sth2 = $cat_db->select ( ['ID'],{ FatherID => $cat_id });
while (my ($child_id) = $sth2->fetchrow_array){
my $sth3 = $link_db->select ( { CategoryID => $child_id, isValidated => 'Yes' });
while (my $hash2 = $sth3->fetchrow_hashref) {
push @output, $hash2;

}
@output = sort {return (rand > 0.5) ? 1 : -1;} @output;
splice (@output,5);
}
return { Random_Loop => \@output }
}

Last edited by:

Evoir: Aug 3, 2002, 11:49 AM

Edit Log: