Gossamer Forum
Home : Products : Gossamer Links : Discussions :

late_by_cat and distinct listing

Quote Reply
late_by_cat and distinct listing
Hi.

Using following global for listing latest_n_by_cat (category downwards) called on category.html (courtsey afinlr)

sub {
my $tags=shift;
my $back;
my $cat_id = $tags->{ID};
my $all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids,$cat_id;
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options('ORDER BY Add_Date DESC','LIMIT 25');
my $condition = GT::SQL::Condition->new( 'isValidated','=','Yes','CategoryID', 'IN', $all_ids);
my $sth = $link_db->select($condition);
while (my $link = $sth->fetchrow_hashref) {
$back .= Links::SiteHTML::display('newlink_cat',$link);
}

return $back;
}

Problem:
A Link may be listed under n sub-ctegories of a category...
This causes the lsiting to appear "n" number of times.

How can "Distinct" be enforced ?

TIA

Thanks
HyTC
==================================
Mail Me If Contacting Privately Is That Necessary.
==================================

Last edited by:

HyperTherm: Mar 31, 2005, 4:55 PM
Quote Reply
Re: [HyperTherm] late_by_cat and distinct listing In reply to
Off the top of my head, I would try
my $sth = $link_db->select(['Distinct(LinkID)'],$condition);

Last edited by:

afinlr: Apr 4, 2005, 1:00 AM
Quote Reply
Re: [afinlr] late_by_cat and distinct listing In reply to
It stops displaying everything (for the global ie).

Thanks
HyTC
==================================
Mail Me If Contacting Privately Is That Necessary.
==================================
Quote Reply
Re: [HyperTherm] late_by_cat and distinct listing In reply to
Try this

sub {
my $tags=shift;
my $back;
my $cat_id = $tags->{ID};
my $all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids,$cat_id;
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options('ORDER BY Add_Date DESC','LIMIT 25');
my $condition = GT::SQL::Condition->new( 'isValidated','=','Yes','CategoryID', 'IN', $all_ids);
my @links = $link_db->select('DISTINCT(LinkID)',$condition)->fetchall_list;
my $sth = $DB->table('Links')->select(GT::SQL::Condition->new('ID','IN',\@links));
while (my $link = $sth->fetchrow_hashref) {
$back .= Links::SiteHTML::display('newlink_cat',$link);
}
return $back;
}

Last edited by:

afinlr: Apr 4, 2005, 9:24 AM
Quote Reply
Re: [afinlr] late_by_cat and distinct listing In reply to
Global symbol "$cond" requires explicit package name at (eval 4351) line 10

Thanks
HyTC
==================================
Mail Me If Contacting Privately Is That Necessary.
==================================
Quote Reply
Re: [HyperTherm] late_by_cat and distinct listing In reply to
Sorry - typo. I've updated the post.
Quote Reply
Re: [afinlr] late_by_cat and distinct listing In reply to
Perfect 10!
Wish someone could add this to rsource section.

Thanks

Thanks
HyTC
==================================
Mail Me If Contacting Privately Is That Necessary.
==================================
Quote Reply
Re: [afinlr] late_by_cat and distinct listing In reply to
The listings are fine but:

$link_db->select_options('ORDER BY Add_Date DESC','LIMIT 25');

This order by... DESC doesn't look to list it With Latest First. It's always the oldest First and the Latest at End of the list.

Any clue
Thanks


Thanks
HyTC
==================================
Mail Me If Contacting Privately Is That Necessary.
==================================
Quote Reply
Re: [HyperTherm] late_by_cat and distinct listing In reply to
Try with Add_Date ASC

Quote Reply
Re: [Payooo] late_by_cat and distinct listing In reply to
I had tried that but it doesn't Help.
Does it work in your case (if you have tried)? If yes wht's the version you are on. I am on Glinks 3 if that could be the issue ... not sure though.

Thanks
HyTC
==================================
Mail Me If Contacting Privately Is That Necessary.
==================================
Quote Reply
Re: [HyperTherm] late_by_cat and distinct listing In reply to
Sorry - that's because it is used in the first select and not the second. Try this:

sub {
my $tags=shift;
my $back;
my $cat_id = $tags->{ID};
my $all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids,$cat_id;
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options('LIMIT 25');
my $condition = GT::SQL::Condition->new( 'isValidated','=','Yes','CategoryID', 'IN', $all_ids);
my @links = $link_db->select('DISTINCT(LinkID)',$condition)->fetchall_list;
my $db = $DB->table('Links');
$db->select_options('ORDER BY Add_Date DESC');
my $sth = $db->select(GT::SQL::Condition->new('ID','IN',\@links));
while (my $link = $sth->fetchrow_hashref) {
$back .= Links::SiteHTML::display('newlink_cat',$link);
}
return $back;
}
Quote Reply
Re: [afinlr] late_by_cat and distinct listing In reply to
Bingo!

:)
Thanks

Thanks
HyTC
==================================
Mail Me If Contacting Privately Is That Necessary.
==================================
Quote Reply
Re: [HyperTherm] late_by_cat and distinct listing In reply to
Hi,
I have the global on a category template with 10 sub-categories, it seems to pull back the new links from the first few sub-categories, then it skips other sub categories altogether.... any thoughts?
George
Quote Reply
Re: [macbethgr] late_by_cat and distinct listing In reply to
Can't really be sure ... but Glinks 3 there were some issues with the import which was causing the Category_tree table getting messed up. In fact when i initially tried this global it never displayed anything except the one's in "The Category" ... found my Category_tree table was absolutely empty after upgrade... taking care of that however fixed the issue fortunately i had data in the test install upgrade Category_tree table, it was the live install upgrade which got messed up.

If there is anything beyond this, then i think the author of the global (afinlr) would be the right person to contact.

Thanks
HyTC
==================================
Mail Me If Contacting Privately Is That Necessary.
==================================

Last edited by:

HyperTherm: Apr 13, 2005, 3:58 AM
Quote Reply
Re: [HyperTherm] late_by_cat and distinct listing In reply to
Thanks,

I rebuilt my category tree, but no help.

I use the following global to list the most popular links in a category and it's sub-categories and it works fine in the new version (not sure who wrote it orginally, but thanks), I think that it can be adapted to work with new links, but not sure what to do to make this happen.


<%popular_cat%>

sub {
my ($all_ids,@list,$output);
my $tags = shift;
my $cat_id = $tags->{ID};
$all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids, $cat_id;
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options ('ORDER BY Hits DESC LIMIT 6');
my $condition = GT::SQL::Condition->new( 'isValidated','=','Yes','CategoryID', 'IN', $all_ids);
my $sth = $link_db->select($condition);
while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
#$output .= qq~<li><a href="$CFG->{db_cgi_url}/jump.cgi?ID=$link->{ID}">$link->{'Title'}</a>~;
}
return $output;
}


Thanks,
George
Quote Reply
Re: [macbethgr] late_by_cat and distinct listing In reply to
Hmm, I think I moved the sort from the first to the second select - but looking at it again, I think it should be in both of them. Is this any better?

sub {
my $tags=shift;
my $back;
my $cat_id = $tags->{ID};
my $all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids,$cat_id;
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options('ORDER BY Add_Date DESC', 'LIMIT 25');
my $condition = GT::SQL::Condition->new( 'isValidated','=','Yes','CategoryID', 'IN', $all_ids);
my @links = $link_db->select('DISTINCT(LinkID)',$condition)->fetchall_list;
my $db = $DB->table('Links');
$db->select_options('ORDER BY Add_Date DESC');
my $sth = $db->select(GT::SQL::Condition->new('ID','IN',\@links));
while (my $link = $sth->fetchrow_hashref) {
$back .= Links::SiteHTML::display('newlink_cat',$link);
}
return $back;
}
Quote Reply
Re: [afinlr] late_by_cat and distinct listing In reply to
Works great.... Thanks!