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
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