Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Count special Links with a Global

Quote Reply
Count special Links with a Global
Hallo,

i have a Problem to count some special Link in a Global.

I add a Column in Table Links called statistik as intr.
with a Value 1or 0.
Now i want to count the Link in the every Category with the value 1 and display them. I wrote a global like :
sub {
my $output;
my $cat_db = $DB->table('Category');
my $cat_id=shift;

my $sth = $cat_db->select ( {'ID' => $cat_id });
while (my ($id) = $sth->fetchrow_array) {
my $all_ids = $DB->table('Category')->children($id);

my $link_db = $DB->table('Links','CatLinks');
my $condition = GT::SQL::Condition->new( 'statistik','=','1','CategoryID', 'IN', \@$all_ids);
my $out = $link_db->count($condition);

$output .= qq ($out);

}
return $output;
}

in subcategory.html i wrote

<small><i>(<%Number_of_Links%>)</i></small> <small><font color=darkblue><i>(<%cat_statistik($ID)%>)</i></font></small>

But i have a problem:
For example

When i select with sqlmonitor the Linkssql where statistik like 1 the value is 1000.

1) If i use my Global the value (statistik=1) of all Links in Categorys is 990
2) In the subcategory the value(statistik=1) of all Links will less then the hole links.

Any help is welcome
Quote Reply
Re: [jupp] Count special Links with a Global In reply to
Hi. Does this global work any better?

Code:
sub {

my $cat_id = $_[0];
my $cat_db = $DB->table('Category');

my $full_name = $cat_db->select ( ['Full_Name'], { 'ID' => $cat_id })->fetchrow;
if !$full_name return "Invalid category ID passed...";

my $sth = $cat_db->select( GT::SQL::Condition->new('Full_Name','LIKE',"$full_name%") ) || return $GT::SQL::error;

my @ids;
while (my $hit = $sth->fetchrow_hashref) {
push(@ids,$hit->{ID});
}

my $count = $DB->table('CatLinks','Links')->count( GT::SQL::Condition->new( 'statistik','=','1','CategoryID', 'IN', \@$ids) );

$count ? return $count || return 0;

}

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: May 27, 2004, 6:03 AM
Quote Reply
Re: [Andy] Count special Links with a Global In reply to
Hi Andy,
many thanks for your help,
but i get these message:



A fatal error has occured:GT::Config (17472): Unable to compile 'cat_statistik' in file '/daten/http/cgi-bin/admin/templates/default/globals.txt': syntax error at (eval 20) line 4, near "if !"
Global symbol "$ids" requires explicit package name at (eval 20) line 11.
syntax error at (eval 20) line 12, near ")
$count "
Global symbol "$count" requires explicit package name at (eval 20) line 12.
Global symbol "$count" requires explicit package name at (eval 20) line 12.
at /daten/http/cgi-bin/admin/GT/Template.pm line 461.
Please enable debugging in setup for more details.

Thanks for look to my problem

Jupp[
Quote Reply
Re: [jupp] Count special Links with a Global In reply to
Sorry about that. It should be;

my $count = $DB->table('CatLinks','Links')->count( GT::SQL::Condition->new( 'statistik','=','1','CategoryID', 'IN', \@$ids) );

Note the ending ; which the old code was missing :( I've updated the above post for you.

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] Count special Links with a Global In reply to
Hi Andy

i have change the global but i get these errormessage

A fatal error has occured:GT::Config (21027): Unable to compile 'cat_statistik' in file '/daten/http/cgi-bin/admin/templates/default/globals.txt': syntax error at (eval 21) line 4, near "if !"
Global symbol "$ids" requires explicit package name at (eval 21) line 11.
syntax error at (eval 21) line 13, at EOF
at /daten/http/cgi-bin/admin/GT/Template.pm line 461.
Please enable debugging in setup for more details.


Many thanks for your help

Jupp
Quote Reply
Re: [jupp] Count special Links with a Global In reply to
Hi Andy

i mixed and modify your and my script and now its run perfectly

this is the result:


sub { my $cat_id = $_[0];
my $output;
my $cat_db = $DB->table('Category');
my $full_name = $cat_db->select ( ['Full_Name'], { 'ID' => $cat_id })->fetchrow;
my $sth = $cat_db->select( GT::SQL::Condition->new('Full_Name','LIKE',"$full_name%") ) || return $GT::SQL::error;
my @ids;
while (my $hit = $sth->fetchrow_hashref) { push(@ids,$hit->{ID});
} my $count = $DB->table('CatLinks','Links')->count( GT::SQL::Condition->new( 'statistik','=','1','CategoryID', 'IN', \@ids) );

$output .= qq ($count);
return $output;


}

many thanks for your help

Jupp Cool Cool Cool Cool