Counting articles in heirarical category system..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arron3
Forum Newbie
Posts: 1
Joined: Sun Sep 07, 2008 9:15 am

Counting articles in heirarical category system..

Post by arron3 »

This has had me stumped for a long time...

Here is the category structure :

Table name :CATEGORIES
Fields : ID,CATEGORY,TITLE

( where CATEGORY is the parent )

Here is my articles stucture:

Table name: LISTINGS
Fields, CATEGORY, (etc)

( CATEGORY has the ID of CATEGORIES table )

So your basic heirarical category system...

What I want to do is count the listings inside of the parent category... ( and the tricky part, all of it's subcategories also ... )

any tips would be great!
User avatar
starram
Forum Commoner
Posts: 58
Joined: Thu Apr 10, 2008 1:27 am
Location: India
Contact:

Re: Counting articles in heirarical category system..

Post by starram »

Please elaborate little more.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Counting articles in heirarical category system..

Post by josh »

If you want the OO theory, look up tree pattern,
If you're designing the database structure you probably want something like

Code: Select all

 
CREATE TABLE `categories` (
  `id` int(15) NOT NULL auto_increment,
  `parent` int(15) NOT NULL default '0',
  `name` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`id`),
);
 
Then you'd use recursion, preferably with the tree pattern, to read out an array or whatever data structure you wanted to work with
Post Reply