Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Number of all related links plus total links

Quote Reply
Number of all related links plus total links
Hello, I've been trying to come up with a global that will display the number of total links plus the number of related links of a category.

Like in:
Cars (112)
Trucks (127)

I found one solution in this forum, but it did not go as deep as it should. It only added numbers from only one or two levels. By the way, my efforts have been futile so far.

What I'm requesting is a global that will display the total number of links of a category, plus the number of links inside its related categories and that categories' subcategories and related categories and so on and so forth. Is this possible?

Here is what I grabbed from this forum (courtesy of Digger):

Code:

sub {
# show the number of total links of a category
# including the number of links of all categories
# related to it

my $tags = shift;
my $KatID = $tags->{ID};
my ($cat_table, $rel_table, $cat_sth, $rel_sth, $RKatID, $rl_count, $count, $output);

$rel_table = $DB->table('CatRelations');
$cat_table = $DB->table('Category');
# get IDs of related categories
$rel_sth = $rel_table->select (['RelatedID'], { CategoryID => $KatID });
while ($RKatID = $rel_sth->fetchrow_array){
# get the number of links from related categories
$cat_sth = $cat_table->select (['Number_of_Links'], { ID => $RKatID });
$rl_count += $cat_sth->fetchrow_array;
}

# get actual number of links from the category
$cat_sth = $cat_table->select (['Number_of_Links'], { ID => $KatID });
$count = $cat_sth->fetchrow_array;

# add the numbers and return them
$output = $count + $rl_count;
return $output;
}


Any help will be appreciated. Thanks.