Hi,
This is TOTALLY untested:
get_rand_from_top_cat
my $current_cat_id = $DB->table('CatLinks')->select( ['CategoryID'], { LinkID > $_[0] } )->fetchrow;
my $cat_name = $DB->table('Category')->select( ['Full_Name'], { ID => $current_cat_id } )->fetchrow;
my @tmp = split /\//, $cat_name;
pop @tmp;
my $higher_up_cat = $DB->table('Category')->select( ['ID'], { Full_Name => join('/',@tmp) } )->fetchrow;
my $all_ids = $DB->table('Category')->children($higher_up_cat);
push @$all_ids, $higher_up_cat;
my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options("ORDER BY RAND() LIMIT 6");
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('isValidated','=','Yes','ID','!=',$_[0]);
my $sth = $db_obj->select (['Links.*'], $cond, $cond2 ) || die $GT::SQL::error;
my @loop;
while (my $hit = $sth->fetchrow_hashref) {
push @loop, $hit;
}
return { relatedlinks => \@links };
}
..call with:
<%if relatedlinks.length%>
<%loop relatedlinks%>
<%include link.html%>
<%endloop%>
<%endif%>
Just be sure you don't just overwrite your old global from the template, in case its not what you want (I'm gonna call it a day in a min, as its gone 8pm ;))
Best bet, is to set it up - just in the footer of detailed.html, so you can see what it looks like / if it works =)
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
This is TOTALLY untested:
get_rand_from_top_cat
Code:
sub { my $current_cat_id = $DB->table('CatLinks')->select( ['CategoryID'], { LinkID > $_[0] } )->fetchrow;
my $cat_name = $DB->table('Category')->select( ['Full_Name'], { ID => $current_cat_id } )->fetchrow;
my @tmp = split /\//, $cat_name;
pop @tmp;
my $higher_up_cat = $DB->table('Category')->select( ['ID'], { Full_Name => join('/',@tmp) } )->fetchrow;
my $all_ids = $DB->table('Category')->children($higher_up_cat);
push @$all_ids, $higher_up_cat;
my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options("ORDER BY RAND() LIMIT 6");
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('isValidated','=','Yes','ID','!=',$_[0]);
my $sth = $db_obj->select (['Links.*'], $cond, $cond2 ) || die $GT::SQL::error;
my @loop;
while (my $hit = $sth->fetchrow_hashref) {
push @loop, $hit;
}
return { relatedlinks => \@links };
}
..call with:
Code:
<%get_rand_from_top_cat($ID)%> <%if relatedlinks.length%>
<%loop relatedlinks%>
<%include link.html%>
<%endloop%>
<%endif%>
Just be sure you don't just overwrite your old global from the template, in case its not what you want (I'm gonna call it a day in a min, as its gone 8pm ;))
Best bet, is to set it up - just in the footer of detailed.html, so you can see what it looks like / if it works =)
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!