Gossamer Forum
Quote Reply
Random Global Questions
I had a long long thread http://www.gossamer-threads.com/...rum.cgi?post=174933; going a while back, but I thought I would start fresh and hopefully it can be easier to follow. I really want to add fuctionality, if someone here can write it.

I have a really nice global that Alex, Paul and Pugdog helped me figure out. (I hope I didn't miss anyone!) What it does is
1) allow you to have random links from a particlar category show up
2) not have any duplicates of those links show at the same time.
3) It creates dynamic (refreshing) random links on static pages.

Global:
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 }
}


Then I create a template called:
random.html with the following in it

<%random_link%>
<%loop Random_Loop%>
<%body_font%>
<div align="left"><a href="<%build_root_url%>/Detailed/<%ID%>.html"><b>
<%Title%>
</b><br>
</A>
<%Description%>
<a href="<%build_root_url%>/Detailed/<%ID%>.html"> more</A></%body_font%> <br>
</div>
<%endloop%>

I then call that template within the category template like this:
<!--#include virtual="/cgi-bin/dir/page.cgi?p=random&Random_CatID=<%ID%>"-->
or
<!--#include virtual="/cgi-bin/dir/page.cgi?p=random&Random_CatID=9"-->

What I want to change
I would love to make it be able to choose from any of the subcats within a category. What happens is that I have:

Category 1
-subcat a
-subcat b
-subcat c

I want to be able to use <!--#include virtual="/cgi-bin/dir/page.cgi?p=random&Random_CatID=<%ID%>"--> and have it pull links from within subcat a,b and c when I put the above ssi in Category 1. (many times there are no links in Category 1)

Can this work? How? Can you explain it?

Last edited by:

Evoir: Aug 2, 2002, 4:36 PM
Subject Author Views Date
Thread Random Global Questions Evoir 8143 Aug 2, 2002, 4:34 PM
Thread Re: [Evoir] Random Global Questions
afinlr 8003 Aug 2, 2002, 5:14 PM
Thread Re: [afinlr] Random Global Questions
Evoir 8080 Aug 3, 2002, 9:24 AM
Thread Re: [Evoir] Random Global Questions
afinlr 8024 Aug 3, 2002, 11:22 AM
Post Re: [afinlr] Random Global Questions
Evoir 7988 Aug 3, 2002, 11:49 AM
Thread Re: [afinlr] Random Global Questions
Paul 8000 Aug 3, 2002, 11:56 AM
Thread Re: [Paul] Random Global Questions
Evoir 8014 Aug 3, 2002, 12:02 PM
Thread Re: [Evoir] Random Global Questions
afinlr 7941 Aug 3, 2002, 12:52 PM
Thread Re: [afinlr] Random Global Questions
Evoir 7944 Aug 7, 2002, 1:08 PM
Post Re: [Evoir] Random Global Questions
Evoir 7882 Aug 8, 2002, 2:45 PM
Thread Re: [Paul] Random Global Questions
afinlr 7970 Aug 3, 2002, 12:18 PM
Thread Re: [afinlr] Random Global Questions
Paul 8022 Aug 3, 2002, 12:43 PM
Thread Re: [Paul] Random Global Questions
Evoir 7893 Sep 13, 2002, 11:41 AM
Thread Re: [Evoir] Random Global Questions
Alex 7933 Sep 13, 2002, 12:34 PM
Thread Re: [Alex] Random Global Questions
Evoir 7846 Sep 13, 2002, 12:49 PM
Thread Re: [Evoir] Random Global Questions
Alex 7871 Sep 13, 2002, 1:42 PM
Post Re: [Alex] Random Global Questions
afinlr 7810 Sep 13, 2002, 3:37 PM
Post Re: [Alex] Random Global Questions
Evoir 7817 Sep 13, 2002, 4:34 PM
Post Re: [Alex] Random Global Questions
Evoir 7807 Sep 13, 2002, 4:37 PM
Post Re: [Alex] Random Global Questions
Evoir 7853 Sep 13, 2002, 4:56 PM