Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Duplication link at new link page

Quote Reply
Duplication link at new link page
Hi
When using the global to show new link, if the link was submit to more then one category it show the link in the page the number of time it submit. So if user submit link to 3 categories in the new link it will display 3 times the same link.
Is there a solution for this:)

The global
sub {
# Displays the Last X new links.
my $new_nr = shift;
my $search_db = $DB->table('Links');
$search_db->select_options ("ORDER BY Add_Date DESC Limit $new_nr");
my $sth = $search_db->select ( { isNew => 'Yes', isValidated => 'Yes' });
my $output;
while (my $link = $sth->fetchrow_hashref) {
$link->{'category_url'} = $CFG->{build_root_url}."/".$link->{'Full_Name'}."/";
$link->{'detailed_url'} = "$CFG->{build_detail_url}/$link->{'ID'}$CFG->{build_extension}";
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}
Quote Reply
Re: [nir] Duplication link at new link page In reply to
Hi,

Try this:

Code:
sub {
# Displays the Last X new links.
my $new_nr = shift;
my $search_db = $DB->table('Links');

$search_db->select_options ("ORDER BY Add_Date DESC Limit $new_nr");

my $sth = $search_db->select ( { isNew => 'Yes', isValidated => 'Yes' });

my $seen;
my $output;
while (my $link = $sth->fetchrow_hashref) {
if ($seen->{$link->{ID})) { next }
$link->{'category_url'} = $CFG->{build_root_url}."/".$link->{'Full_Name'}."/";
$link->{'detailed_url'} = "$CFG->{build_detail_url}/$link->{'ID'}$CFG->{build_extension}";
$output .= Links::SiteHTML::display ('link', $link);
$seen->{$link->{ID}} = 1;
}
return $output;
}

(bits in red are new code)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: Sep 5, 2007, 7:13 AM
Quote Reply
Re: [Andy] Duplication link at new link page In reply to
Hi AndySmile
I actually use this function:)
And I it not give me error when I try it.

sub {
use GT::SQL::Condition;
my $user = $_[0];
my $id = $_[1];
my $catid = $_[2];
my $tbl = $DB->table('CatLinks','Links');
$tbl->select_options('ORDER BY Add_Date DESC Limit 10');
my $cond = new GT::SQL::Condition;
$cond->add('isValidated','=','Yes');
$cond->add(Cast => Like => "%$user%");
if ($catid) {
my $all_ids = $DB->table('Category')->children($catid);
$cond->add('CategoryID','IN',\@$all_ids); }
my $sth = $tbl->select( $cond ) || return $GT::SQL::error;
my $seen;
my @back;
while (my $hit = $sth->fetchrow_hashref) {
if ($seen->{$link->{ID})) { next };
$seen->{$link->{ID}) = 1;
push @back, $hit;

} my $exists; if ($back[0]) { $exists = 1; } else { $exists = ''; }
return { user_link_loop => \@back, exists => $exists }; }
Quote Reply
Re: [nir] Duplication link at new link page In reply to
Hi,

Ah, sorry - my changes had a typo =)

Code:
$seen->{$link->{ID}) = 1;

..should have been:

Code:
$seen->{$link->{ID}} = 1;

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Duplication link at new link page In reply to
Thanks Andy' it workSmileWinkCool
Quote Reply
Re: [nir] Duplication link at new link page In reply to
Hi,

Glad to hear it =)

For anyone else interested in using the modified global, my post has the fixes made, so should work fine :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!