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!
Counting articles in heirarical category system..
Moderator: General Moderators
Re: Counting articles in heirarical category system..
Please elaborate little more.
Re: Counting articles in heirarical category system..
If you want the OO theory, look up tree pattern,
If you're designing the database structure you probably want something like
Then you'd use recursion, preferably with the tree pattern, to read out an array or whatever data structure you wanted to work with
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`),
);