Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Deleting categories with zero links...

Quote Reply
Deleting categories with zero links...
Is there an easy way to do this? Perhaps with a SQL statement?

Sean
Quote Reply
Re: [SeanP] Deleting categories with zero links... In reply to
I have done this, and no, it is not simple. The reason is, you have to check to see if the category has any subcategories before removing it.

In case you are wondering:

Create a new column called hasChildren. Write a script which sets hasChildren to YES or NO.

Code:
my $total_categories = $cat->count;
print "Total Categories: $total_categories<br>"; my $sth = $cat->select;
while (my $category = $sth->fetchrow_hashref) {
my $hc = ($cat->count( { FatherID => $category->{ID} } )) ? 'Yes' : 'No';
$cat->update( { haschildren => $hc }, { ID => $category->{ID} } );
}

Last edited by:

Ian: Sep 9, 2002, 8:19 AM
Quote Reply
Re: [SeanP] Deleting categories with zero links... In reply to
The Number_of_Links column should give you the total of all links within that category (including subcategories). So if it's zero, you can savely delete (well, safely, try it on a testing installation first....)

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [SeanP] Deleting categories with zero links... In reply to
Do a "Repair Tables" before doing it too.
Quote Reply
Re: [Paul] Deleting categories with zero links... In reply to
Excellent... I'll give it a go... Thanks everyone!

Sean
Quote Reply
Re: [SeanP] Deleting categories with zero links... In reply to
Hi

I do this on regular basis to avoid Empty categories by editors:

Do:

1- Do Repair tables.

2- Make sure to validate any pending links

3- Go to Database> categories:Delete> Then endter Number of Links = 0

Max hits 100, Check match any,
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory