Gossamer Forum
Quote Reply
New Links Problem
The following code displays new links on a page.
The problem is that links are displayed BEFORE they are validated.
Any suggestions on how to make only links that have been validated display?

sub {
# Displays the last 9 links.
my $tags = shift;
my $table = $DB->table('Links');
$table->select_options ('ORDER BY Add_Date DESC', 'LIMIT 9');
my $sth = $table->select;
my @output;
while (my $link = $sth->fetchrow_hashref) {
$link->{Title} = (length $link->{Title} > 28) ? substr($link->{Title},0,28) . ' ...' : $link->{Title};
push (@output, $link);
}
return { New_Links_loop => \@output };
}

~ ERASER


Free JavaScripts @ Insight Eye
Quote Reply
Re: [Eraser] New Links Problem In reply to
I think you need to pass in a hashref like:

{ isValidated => 'Yes' }
Quote Reply
Re: [PaulW] New Links Problem In reply to
Just to clarify that, Paul means change:
my $sth = $table->select;
to:
my $sth = $table->select({ isValidated => 'Yes' });

Adrian
Quote Reply
Re: [brewt] New Links Problem In reply to
Excellent.

Works a treat.

Thanks chaps.


~ ERASER


Free JavaScripts @ Insight Eye
Quote Reply
Re: [brewt] New Links Problem In reply to
Hi,

Is there a way to define a specific category within the tag and global?

IE:

<%newlinks 'catnameonumberhere'%>

And how would it change this global?

sub {
# Displays the newest links on the home page.
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 5');
$sth = $search_db->select ( { isNew => 'Yes', isValidated => 'Yes' });
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link1', $link);
}
return $output;
}



Thanks!

Brian
Quote Reply
Re: [Teambldr] New Links Problem In reply to
>>
<%newlinks 'catnameonumberhere'%>
<<

It would be:

<%newlinks('number_here')%>

Then you'd grab it in the global with:

my $cat = shift;

You'd have to add CatLinks into the table() call and then add:

CategoryID => $cat

....into the select() call.

Last edited by:

Paul: Mar 18, 2003, 10:19 AM
Quote Reply
Re: [Paul] New Links Problem In reply to
Hi Paul,

So if I get this I would do the following:

<%newcatlinks('number_here')%>

Global name: newcatlinks

Code:
sub {
# Displays the newest links on the home page.
my ($output,$sth,$link);
my $cat = shift;
my $search_db = $DB->table('CatLinks', 'Links');
$search_db->select_options ('CategoryID => $cat', 'ORDER BY Add_Date DESC Limit 5');
$sth = $search_db->select ( { isNew => 'Yes', isValidated => 'Yes' });
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link1', $link);
}
return $output;
}


Does that look right Paul?



Thanks!

Brian
Quote Reply
Re: [Teambldr] New Links Problem In reply to
Yep looks pretty good.
Quote Reply
Re: [Teambldr] New Links Problem In reply to
Whoops, I missed your quotes.

Change:

'CategoryID => $cat'

to...

CategoryID => $cat

...and move it into the select() call not select_options()

Last edited by:

Paul: Mar 18, 2003, 10:34 AM
Quote Reply
Re: [Paul] New Links Problem In reply to
OK...lets see if I have it now... :)



Code:
sub {
# Displays the newest links on the home page.
my ($output,$sth,$link);
my $cat = shift;
my $search_db = $DB->table('CatLinks', 'Links');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 5');
$sth = $search_db->select ( {isNew => 'Yes', isValidated => 'Yes', CategoryID => $cat });
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link1', $link);
}
return $output;
}

Last edited by:

Teambldr: Mar 18, 2003, 10:48 AM
Quote Reply
Re: [Teambldr] New Links Problem In reply to
Hehe, closer, just move CategoryID = >$cat to the right side of the { Wink
Quote Reply
Re: [Paul] New Links Problem In reply to
I was changing it while you were posting...LOL...I saw it after I posted it.

I made the change above
Quote Reply
Re: [Paul] New Links Problem In reply to
Hey Paul,

If I wanted to change the output formatting to use a template called "newcatlinks.html" how would I structure it in this global?


Would it be like this?

$output .= Links::SiteHTML::display ('newcatlinks', $link);


Thanks again for the help...

Brian

Last edited by:

Teambldr: Mar 18, 2003, 3:54 PM
Quote Reply
Re: [Teambldr] New Links Problem In reply to
Yeah that should work.
Quote Reply
Re: [Paul] New Links Problem In reply to
Very cool...



Thanks again!Smile