Page 1 of 1

Counting articles in heirarical category system..

Posted: Sun Sep 07, 2008 9:15 am
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!

Re: Counting articles in heirarical category system..

Posted: Sun Sep 07, 2008 12:26 pm
by starram
Please elaborate little more.

Re: Counting articles in heirarical category system..

Posted: Mon Sep 08, 2008 12:54 am
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