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

Changing output in random links global

Quote Reply
Changing output in random links global
Hi, I am trying to change the global that selects three links at random
to diplay. This is the code:

sub {
my $link_db = $DB->table('Links');
my $total = $link_db->count ( { isValidated => 'Yes' });
my $output;
for (1 .. 3) {
my $rand = int (rand() * $total);
$link_db->select_options ("LIMIT $rand, 1");
my $sth = $link_db->select ({ isValidated => 'Yes' });
my $link = $sth->fetchrow_hashref;
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}

I want to change it so that rather than outputing the link like it looks in link.html I can control the output and only show the title and description. An example of this would be the 'last 10 links' global. Here is code for that:

sub {
my $tags = shift;
my $table = $DB->table('Links');
$table->select_options ('ORDER BY Add_Date DESC', 'LIMIT 10');
my $sth = $table->select;
my @output;
while (my $link = $sth->fetchrow_hashref) {
$link->{Description} = (length $link->{Description} > 70) ? substr($link->{Description},0,70) . ' ...' : $link->{Description};
push (@output, $link);
}
return { Lastlinks10_loop => \@output };
}

This is in the template:

<%Lastlinks10%>
<%loop Lastlinks10_loop%>
<b>&#183;&nbsp;</b><a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>" target="_blank"><b><%Title%></b></a>
<%if Description%>
<%Description%>
<%endif%>
<font face="verdana,arial" size="1" color="#cccccc">(Added: <%Add_Date%>)</font><br>
<%endloop%>

I guess what I am asking is how can I have the same output in the random links global as there is in the lastlinks? I have tried without luck. Any help would be greatly appreciated.

Thanks,

Jay

Last edited by:

LGJ31: Jan 23, 2002, 6:12 PM
Subject Author Views Date
Thread Changing output in random links global LGJ31 5512 Jan 23, 2002, 5:57 PM
Thread Re: [LGJ31] Changing output in random links global
BryanL 5410 Jan 23, 2002, 8:23 PM
Thread Re: [BryanL] Changing output in random links global
LGJ31 5418 Jan 23, 2002, 9:27 PM
Thread Re: [LGJ31] Changing output in random links global
Bruha 5043 Nov 18, 2006, 1:57 PM
Thread Re: [Bruha] Changing output in random links global
Dinky 5064 Nov 18, 2006, 9:18 PM
Thread Re: [Dinky] Changing output in random links global
Bruha 5088 Nov 18, 2006, 11:57 PM
Thread Re: [Bruha] Changing output in random links global
Dinky 5063 Nov 20, 2006, 7:59 PM
Thread Re: [Dinky] Changing output in random links global
Bruha 5060 Nov 21, 2006, 12:01 AM
Thread Re: [Bruha] Changing output in random links global
Dinky 5034 Nov 21, 2006, 12:37 AM
Post Re: [Dinky] Changing output in random links global
Bruha 4982 Nov 21, 2006, 2:17 AM