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

Re: [Evoir] Random Global Questions

Quote Reply
Re: [Evoir] Random Global Questions In reply to
Hmm, let's clean that up a bit. Try:

Code:
sub {
my $tags = shift;
my $limit = ($tags->{Random_Limit} =~ /^(\d+)$/) ? $1 : 3;
my @parents = $IN->param('Random_CatID');
my @cat_ids;
foreach my $id (@parents) {
push @cat_ids, $id, $DB->table('Category')->children($id);
}
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options ('ORDER BY RAND()', "LIMIT $limit");
my $condition = GT::SQL::Condition->new( 'Description', 'IS NOT', \'NULL','isValidated','=','Yes');
if (@cat_ids) {
$condition->add('CategoryID', 'IN', \@cat_ids);
}
my $sth = $link_db->select($condition);
my @output;
while (my $hash = $sth->fetchrow_hashref) {
push @output, $hash;
}
return { Random_Loop => \@output }
}


This is a little different in that it will pick random link from the category you pass in, or any subcategory, not just the first level of subcategory.

To call this, just do:

<!--#include virtual="/cgi-bin/page.cgi?page=random&Random_CatID=1&Random_CatID=2"-->

to get 3 random links from anywhere inside category 1 or 2.

Cheers,

Alex
--
Gossamer Threads Inc.
Subject Author Views Date
Thread Random Global Questions Evoir 6906 Aug 2, 2002, 4:34 PM
Thread Re: [Evoir] Random Global Questions
afinlr 6783 Aug 2, 2002, 5:14 PM
Thread Re: [afinlr] Random Global Questions
Evoir 6861 Aug 3, 2002, 9:24 AM
Thread Re: [Evoir] Random Global Questions
afinlr 6803 Aug 3, 2002, 11:22 AM
Post Re: [afinlr] Random Global Questions
Evoir 6770 Aug 3, 2002, 11:49 AM
Thread Re: [afinlr] Random Global Questions
Paul 6781 Aug 3, 2002, 11:56 AM
Thread Re: [Paul] Random Global Questions
Evoir 6793 Aug 3, 2002, 12:02 PM
Thread Re: [Evoir] Random Global Questions
afinlr 6722 Aug 3, 2002, 12:52 PM
Thread Re: [afinlr] Random Global Questions
Evoir 6724 Aug 7, 2002, 1:08 PM
Post Re: [Evoir] Random Global Questions
Evoir 6663 Aug 8, 2002, 2:45 PM
Thread Re: [Paul] Random Global Questions
afinlr 6751 Aug 3, 2002, 12:18 PM
Thread Re: [afinlr] Random Global Questions
Paul 6802 Aug 3, 2002, 12:43 PM
Thread Re: [Paul] Random Global Questions
Evoir 6671 Sep 13, 2002, 11:41 AM
Thread Re: [Evoir] Random Global Questions
Alex 6714 Sep 13, 2002, 12:34 PM
Thread Re: [Alex] Random Global Questions
Evoir 6627 Sep 13, 2002, 12:49 PM
Thread Re: [Evoir] Random Global Questions
Alex 6652 Sep 13, 2002, 1:42 PM
Post Re: [Alex] Random Global Questions
afinlr 6593 Sep 13, 2002, 3:37 PM
Post Re: [Alex] Random Global Questions
Evoir 6599 Sep 13, 2002, 4:34 PM
Post Re: [Alex] Random Global Questions
Evoir 6588 Sep 13, 2002, 4:37 PM
Post Re: [Alex] Random Global Questions
Evoir 6634 Sep 13, 2002, 4:56 PM