Gossamer Forum
Home : Products : Gossamer Links : Discussions :

New & Updated By Category

Quote Reply
New & Updated By Category
I have the following global for displaying the newest links by category:

new_by_cat

############################

sub {
my $tags = shift;
my $cat = $tags->{'Full_Name'};
my $output;
my $sth;
my $link;

use GT::SQL::Condition;

my $search_db = $DB->table('Links','CatLinks','Category');
$search_db->select_options ('GROUP BY LinkID ORDER BY Add_Date DESC Limit 5');
$sth = $search_db->select (['Links.ID', 'Links.Description', 'Links.Title', 'Links.Add_Date', 'Category.Full_Name', 'Category.Name'], GT::SQL::Condition->new(['Full_Name', 'LIKE', $cat .'%'], ['isNew', '=', 'Yes'], ['isValidated', '=', 'Yes']));

while ($link = $sth->fetchrow_hashref) {

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

}

return $output;

}

How would i get it to show the updated links also?

Regards,

Blake
Quote Reply
Re: [blakeb] New & Updated By Category In reply to
Hi,

I would think that is you addas below it would work (not tested):
Code:
sub {
my $tags = shift;
my $cat = $tags->{'Full_Name'};
my $output;
my $sth;
my $link;

use GT::SQL::Condition;

my $search_db = $DB->table('Links','CatLinks','Category');
$search_db->select_options ('GROUP BY LinkID ORDER BY Add_Date DESC Limit 5');
$sth = $search_db->select (['Links.ID', 'Links.Description', 'Links.Title', 'Links.Add_Date', 'Category.Full_Name', 'Category.Name'], GT::SQL::Condition->new(['Full_Name', 'LIKE', $cat .'%'], ['isNew', '=', 'Yes'], ['isValidated', '=', 'Yes'],['isChanged', '=', 'Yes']));

while ($link = $sth->fetchrow_hashref) {

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

}

return $output;

}

Cheers
Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] New & Updated By Category In reply to
Already tried it, doesn't work, nothing shows up........ Unsure
Quote Reply
Re: [blakeb] New & Updated By Category In reply to
hmmm... have you tried removing the isNew statement - just to see if that works?

Klaus

http://www.ameinfo.com
Quote Reply
Re: [blakeb] New & Updated By Category In reply to
You need an or condition to show links which are either new or updated. Something like this

sub {
my $tags = shift;
my $cat = $tags->{'ID'};
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;
my $output;
my $sth;
my $link;
use GT::SQL::Condition;

my $search_db = $DB->table('Links','CatLinks','Category');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 5');
my $cond = GT::SQL::Condition->new( ['isNew', '=', 'Yes'], ['isValidated', '=', 'Yes']); $cond->bool('or');
$sth = $search_db->select (['Links.ID', 'Links.Description', 'Links.Title', 'Links.Add_Date', 'Category.Full_Name', 'Category.Name'], GT::SQL::Condition->new(['CategoryID', 'IN', \@$all_ids], $cond));

while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link1', $link);
}

return $output;

}
Quote Reply
Re: [afinlr] New & Updated By Category In reply to
Guess you still need ['isChanged', '=', 'Yes'] in there

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] New & Updated By Category In reply to
Wow - think I must be tired! Sorry about that.

sub {
my $tags = shift;
my $cat = $tags->{'ID'};
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;
my $output;
my $sth;
my $link;
use GT::SQL::Condition;

my $search_db = $DB->table('Links','CatLinks','Category');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 5');
my $cond = GT::SQL::Condition->new( ['isNew', '=', 'Yes'], ['isChanged', '=', 'Yes']); $cond->bool('or');
$sth = $search_db->select (['Links.ID', 'Links.Description', 'Links.Title', 'Links.Add_Date', 'Category.Full_Name', 'Category.Name'], GT::SQL::Condition->new('CategoryID', 'IN', \@$all_ids, 'isValidated', '=', 'Yes', $cond));

while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link1', $link);
}

return $output;

}
Quote Reply
Re: [afinlr] New & Updated By Category In reply to
Thanks, works great! Laugh