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

Products: Gossamer Links: Development, Plugins and Globals: Re: [Evoir] Link of the day..: Edit Log

Here is the list of edits for this post
Re: [Evoir] Link of the day..
Hi,

This is getting more complex. You want something like:

Code:
Random_Link => 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;
}
return { Random_Loop => \@output }
}

This will only work with MySQL 3.23, as you can't do ORDER BY RAND() on older mysql's. To use this you would put:

<%Random_Link%>
<%loop Random_Loop%>
Random: <%Title%>: <%URL%><BR>
<%endloop%>

or if only for a specific category, you would do:

<%set Random_Category = 3%>
... rest as normal.

Hope this helps,

Alex
--
Gossamer Threads Inc.

Last edited by:

Alex: Nov 21, 2001, 5:52 PM

Edit Log: