Gossamer Forum
Quote Reply
Random global
Hi, I'd like to get this global changed so that it only fetches validated listings:

Code:

sub {
my $tags = shift;
my $link_db = $DB->table('Links','CatLinks');
my $cat_id = $tags->{Random_CatID};
my $limit = $tags->{Random_Limit} || 1;
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 }
}

cdkrg

Able2Know :: Ajooja Directory
Quote Reply
Re: [cdkrg] Random global In reply to
This is a random sub I'm using, it may work for you or change yours to suit.

sub {
my $link_db = $DB->table('Links');
$link_db->select_options ("ORDER BY rand()","LIMIT 10");
my $sth = $link_db->select ({isValidated => 'Yes' });
my $output;
while (my $link = $sth->fetchrow_hashref){
$output .= Links::SiteHTML::display ('random_link', $link);
}
return $output;
}

Regards

minesite
Quote Reply
Re: [minesite] Random global In reply to
Thanks, how are you invoking the global? With a tag? A random link template?

cdkrg

Able2Know :: Ajooja Directory
Quote Reply
Re: [cdkrg] Random global In reply to
Both,
Global is call in your pages via the global name tag <%random_link%>

('random_link', $link); is the Template name.

Global displays the random_link.html template which holds what you want to display.
i.e. Logo for instance
<a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>" target="_blank">
<img src="<%build_images_url%>/logo/<%Logo%>" border="0" width="120" height="90"></a>

So place the <%random_link%> on the page were you want the random link to be displayed.
Make up a template with the code you need displayed [ as above] and put the random_link.html template in the template directory.
Change the global to display 5,10 or how many links you want and it should be good to go.

Regards

minesite

Last edited by:

minesite: Jul 26, 2004, 4:58 AM
Quote Reply
Re: [minesite] Random global In reply to
Thanks! A question, are all the link variables available with that global?

cdkrg

Able2Know :: Ajooja Directory
Quote Reply
Re: [cdkrg] Random global In reply to
I believe so.

Regards

minesite
Quote Reply
Re: [minesite] Random global In reply to
how do I get these in a table of 3 columns?