Alex,
Thanks for helping! I may have messed something up, because I just don't understand the perl. Here is what I came up with:
sub {
my $tags = shift;
my $link_db = $DB->table('Links','CatLinks');
my $cat_id = $tags->{Random_CatID};
my @cat_ids = $IN->param('Random_CatID');
my $limit = $tags->{Random_Limit} || 3;
my (@output, $sth);
$link_db->select_options ('ORDER BY RAND()', "LIMIT $limit");
my $condition = GT::SQL::Condition->new( 'Description', 'IS NOT', \'NULL','isValidated','=','Yes');
if ($cat_id) {
$sth = $link_db->select ($condition, { CategoryID => $cat_ids });
}
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 ($condition, { CategoryID => $child_ids, isValidated => 'Yes' });
while (my $hash2 = $sth3->fetchrow_hashref) {
push @output, $hash2;
}
}
@output = sort {return (rand > 0.5) ? 1 : -1;} @output;
splice (@output,$limit);
return { Random_Loop => \@output }
}
Is this correct? (I got no results)
Thanks again
Thanks for helping! I may have messed something up, because I just don't understand the perl. Here is what I came up with:
sub {
my $tags = shift;
my $link_db = $DB->table('Links','CatLinks');
my $cat_id = $tags->{Random_CatID};
my @cat_ids = $IN->param('Random_CatID');
my $limit = $tags->{Random_Limit} || 3;
my (@output, $sth);
$link_db->select_options ('ORDER BY RAND()', "LIMIT $limit");
my $condition = GT::SQL::Condition->new( 'Description', 'IS NOT', \'NULL','isValidated','=','Yes');
if ($cat_id) {
$sth = $link_db->select ($condition, { CategoryID => $cat_ids });
}
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 ($condition, { CategoryID => $child_ids, isValidated => 'Yes' });
while (my $hash2 = $sth3->fetchrow_hashref) {
push @output, $hash2;
}
}
@output = sort {return (rand > 0.5) ? 1 : -1;} @output;
splice (@output,$limit);
return { Random_Loop => \@output }
}
Is this correct? (I got no results)
Thanks again