Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Counting of Links

Quote Reply
Counting of Links
I have searched the forums for this to no avail. I have "copied" links into multiple categories; however, the total count of links is being skewed.

For example, say I have two categories: Category A and Category B. When I put the same link in both categories, shouldn't my total number of links be 1? Mine is showing 2.

Thanks.
Quote Reply
Re: [Jobu] Counting of Links In reply to
That's because <%grand_total%> in home.html counts the CatLinks table. What you want it to do is count the Links table.

[Post edited to remove incorrect global (MJB)]

Last edited by:

MJB: Jun 16, 2006, 8:46 AM
Quote Reply
Re: [MJB] Counting of Links In reply to
Thanks, MJB. I did this, however, when I now try to load home.html I get the following error:

Quote:

A fatal error has occured:
Can't call method "fetchrow_array" on an undefined value at (eval 20) line 2.

Please enable debugging in setup for more details.

Quote:



Any ideas?

Thanks,

AD
Quote Reply
Re: [Jobu] Counting of Links In reply to
OK, scrap the last and use this:

Code:
sub { # show total number of Links (without commas - 123456)
$DB->table('Links')->count({isValidated => 'Yes'})
}
Quote Reply
Re: [MJB] Counting of Links In reply to
Great, thanks! That works great. Now, is there a way to do it so that commas are added, or is that what was causing the problem?
Quote Reply
Re: [Jobu] Counting of Links In reply to
Untested:

Code:
sub { # show total number of actual Links (with commas - 123,456)
my $tags = shift;
local $_ = $DB->table('Links')->count({isValidated => 'Yes'});
return 0 unless defined $_;
1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
return $_;
}

I don't have over 999 links so please let me know if it works Wink
Quote Reply
Re: [MJB] Counting of Links In reply to
I don't have over 999 links either, yet, but no errors when I run it so so far so good. When we get over 999, I will let you know!

Thanks again.
Quote Reply
Re: [MJB] Counting of Links In reply to
This may be quicker, as it simply gets the category counts (Direct_Links) from the lsql_Category table :)

Code:
sub {
my $tmp = $DB->table('Category')->select( ['SUM(Direct_Links)'] )->fetchrow;
my $tmp2 = reverse $tmp;
$tmp2 = sprintf "%.2f", $tmp2;
$tmp2 =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
return scalar reverse $tmp2;
}


hope that helps.

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!
Post deleted by pacifico In reply to