Gossamer Forum
Home : Products : Gossamer Links : Discussions :

List Subcategory + Total New Links

Quote Reply
List Subcategory + Total New Links
Hi All,

Below is the tag for display subcategory by specific category ID, my problem is, how do i display total new links beside the subcategory, for example:

Subcategory1 (20 New)
Subcategory2 (5 New)
Subcategory3 (0 New)
Subcategory4 (8 New)

Tag for display subcategory specific by Category ID:
sub {
my $output;
my $cat_db = $DB->table('Category');
my $cat_id = '226';
$cat_db->select_options('ORDER BY Full_Name');
my $sth = $cat_db->select ( {'FatherID' => $cat_id}, ['Full_Name','Name'] );
while (my ($cat,$heading) = $sth->fetchrow_array) {
my $url = $cat_db->as_url($cat);
$output .= qq~$heading~;
}
return $output;
}


Please help and thanks so much.
Quote Reply
Re: [reenee] List Subcategory + Total New Links In reply to
Something like this I think:

sub {
my $output;
my $cat_db = $DB->table('Category');
my $cat_id = '226';
$cat_db->select_options('ORDER BY Full_Name');
my $sth = $cat_db->select ( {'FatherID' => $cat_id}, ['ID','Full_Name','Name'] );
while (my ($id,$cat,$heading) = $sth->fetchrow_array) {
my $linkdb = $DB->table('Links','CatLinks');
my $count = $linkdb->count ({'CategoryID'=>$id, isNew=>'Yes'});
#my $url = $cat_db->as_url($cat);
$output .= qq~$heading ($count New)~;
}
return $output;
}
Quote Reply
Re: [afinlr] List Subcategory + Total New Links In reply to
Thank you so much afinlr, its near to work, below is the result for that tag:

Arabic (0 New)Chinese (0 New)English (1 New)Hindi (0 New)Japanese (0 New)Malay (2 New)Tamil (0 New)Themes (0 New)

But i'm really confuse because all total new links is 54 based on specific category using tag below:


sub {
my ($all_ids);
my $cat_id = 243;
$all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids,$cat_id;
my $link_db = $DB->table('Links','CatLinks');
my $condition = GT::SQL::Condition->new( 'isValidated','=','Yes','isNew','=','Yes','CategoryID', 'IN', \@$all_ids);
my $count = $link_db->count($condition);

return $count;
}



Pleasse help and thank you.

Last edited by:

reenee: Jul 5, 2003, 12:47 PM
Quote Reply
Re: [reenee] List Subcategory + Total New Links In reply to
Yes sorry, you can just add it to the end

my $count = $linkdb->count ({CategoryID=>$id, isNew=>'Yes', isValidated=>'Yes'});
Quote Reply
Re: [afinlr] List Subcategory + Total New Links In reply to
Oopss, you so fast, thank you, but now the result is:

Arabic (0 New)Chinese (0 New)English (0 New)Hindi (0 New)Japanese (0 New)Malay (0 New)Tamil (0 New)Themes (0 New)

And tag after modification is:

sub {
my $output;
my $cat_db = $DB->table('Category');
my $cat_id = '243';
$cat_db->select_options('ORDER BY Full_Name');
my $sth = $cat_db->select ( {'FatherID' => $cat_id}, ['ID','Full_Name','Name'] );
while (my ($id,$cat,$heading) = $sth->fetchrow_array) {
my $linkdb = $DB->table('Links','CatLinks');
my $count = $linkdb->count ({CategoryID=>$id, isNew=>'Yes', isValidated=>'Yes'});
#my $url = $cat_db->as_url($cat);
$output .= qq~$heading ($count New)~;
}
return $output;
}

But using tag below is showing 54 new links:

sub {
my ($all_ids);
my $cat_id = 243;
$all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids,$cat_id;
my $link_db = $DB->table('Links','CatLinks');
my $condition = GT::SQL::Condition->new( 'isValidated','=','Yes','isNew','=','Yes','CategoryID', 'IN', \@$all_ids);
my $count = $link_db->count($condition);

return $count;
}



Please help.

Last edited by:

reenee: Jul 5, 2003, 12:54 PM
Quote Reply
Re: [reenee] List Subcategory + Total New Links In reply to
That's the difference between new links in that category and new links in that category and all its subcategories. I think you want this:

sub {
my $output;
my $cat_db = $DB->table('Category');
my $cat_id = '243';

$cat_db->select_options('ORDER BY Full_Name');
my $sth = $cat_db->select ( {'FatherID' => $cat_id}, ['ID','Full_Name','Name'] );
while (my ($id,$cat,$heading) = $sth->fetchrow_array) {
my $all_ids = $DB->table('Category')->children($id);

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

#my $url = $cat_db->as_url($cat);
$output .= qq~$heading ($count New)~;
}
return $output;
}

Last edited by:

afinlr: Jul 5, 2003, 1:04 PM
Quote Reply
Re: [afinlr] List Subcategory + Total New Links In reply to
Hi,

Sorry again, its was an error come out with new tag:

Global symbol "$all_ids" requires explicit package name at (eval 391) line 5.
Global symbol "$all_ids" requires explicit package name at (eval 391) line 6.
Global symbol "$all_ids" requires explicit package name at (eval 391) line 11.




Please help.
Quote Reply
Re: [reenee] List Subcategory + Total New Links In reply to
Sorry too fast trying it out! I made a couple of changes Wink
Quote Reply
Re: [afinlr] List Subcategory + Total New Links In reply to
Now its works,



Thank you so much Laugh
Quote Reply
Re: [afinlr] List Subcategory + Total New Links In reply to
sub {
my $output;
my $cat_db = $DB->table('Category');
my $cat_id = '243';

Afnir how do I need to use this code so that cat_id take the value of the category being viewed?

In otherwords, so that it can de displayed in category.html

Quote Reply
Re: [nt6] List Subcategory + Total New Links In reply to
You can either use

$tags = shift;
$cat_id = $tags->{'category_id'};

or you can put the ID in the call to the global <%globalname($ID)%>

and use $cat_id=shift;