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

Will this Random Global of mine work???

Quote Reply
Will this Random Global of mine work???
Hello,

I'm just starting to learn how these Perl globals work so I've attepted to create the following global to perform the following tasks on my site:

1. Display 10 or so random templates from only links with is_partner => 'Yes' , isValidated => 'Yes', has_content => 'Yes'

2. Display No Duplicates

3. Loop Results

Here's the global I've pieced together from several other globals written by Alex and few others...

random_gallerys:

sub {
my $tags = shift;
my $link_db = $DB->table('Links');
my $limit = $tags->{Random_Limit} || 10;
my (@output, $sth);
$link_db->select_options ('ORDER BY RAND()', "LIMIT $limit");
$sth = $link_db->select ( { is_partner => 'Yes', isValidated => 'Yes', has_content => 'Yes' });
while (my $hash = $sth->fetchrow_hashref) { push @output, $hash; }
return { Random_Loop => \@output }
}

Called like:

<%Random_Link%>
<%loop Random_Loop%>
Random: <%Title%>: <%URL%> <%content1%> and a bunch of template stuff!<BR>
<%endloop%>



The goal is to have LinksSQL build my site daily to constantly display fresh content from the links listed at my site.

Should this global do the trick for me????

Is there a more efficient way of writing it??? (Seem like searches are begining to slow as I continue to add globals)

Random_Limit would have to be a column in the links table right??? So it's saying Random_Limit "or" 10 ( whatever number to limit results )?

Is there a way to include 'ORDER BY HITS DESC' along with 'ORDER BY RAND()' ??? I was hoping to have the ability to pull the random links AND display them looped in order by hits. It is not a must though.

Hopefully some of that made sense.

Thanks for any suggestion or comments you all would be willing to offer! I just can't test it out at this point but would like to be preparing my templates if it will work.

Jonze
Subject Author Views Date
Thread Will this Random Global of mine work??? Jonze 3209 Sep 10, 2002, 4:48 PM
Thread Re: [Jonze] Will this Random Global of mine work???
Alex 3122 Sep 11, 2002, 10:35 AM
Thread Re: [Alex] Will this Random Global of mine work???
Paul 3136 Sep 11, 2002, 10:37 AM
Thread Re: [Paul] Will this Random Global of mine work???
Alex 3119 Sep 11, 2002, 10:41 AM
Thread Re: [Alex] Will this Random Global of mine work???
Paul 3123 Sep 11, 2002, 10:42 AM
Thread Re: [Paul] Will this Random Global of mine work???
Alex 3124 Sep 11, 2002, 10:43 AM
Post Re: [Alex] Will this Random Global of mine work???
Paul 3102 Sep 11, 2002, 10:46 AM
Post Re: [Alex] Will this Random Global of mine work???
Jonze 3095 Sep 11, 2002, 2:47 PM