GSimpson
10-22-2009, 12:59 PM
Hey there,
I'm currently building a script of my own that categorizes articles for a blog.
I've got different categories, they're all stored within a single MYSQL table named 'categories', with three pieces of information each. id, title and parent. (ID is a primary key, title is the category name and parent is if this category is a sub category within another)
I've got the basic browsing sorted, using URL variables to move up and down the category levels, but the thing I can't work out, is how to display lower level categories articles. I have another table, 'articles' which contains this information 'id, title, content, category'
Obviously, when browsing the category tree, I can use a mysql_query to display articles marked with the same category as the one being viewed, but I can't find the lower level category articles with the ones within that category.
If I have these in my categories table:
id(3), title(Sample3), parent(0)
id(4), title(Sample4), parent(3)
id(5), title(Sample5), parent(3)
id(6), title(Sample6), parent(5)
So on the link article-list.php?cat=3, with the query I'm doing at the moment, it will show anything from sample4, and sample5, but I don't know how to include blog articles marked with category 6 aswell. Obviously, if I was only browsing category 5, it would show articles from that, and from category 6 too.
Have I structured my tables wrong to complete the task I'm trying to do? I know they're basic tables, but they're only for example. I would google this, if I knew exactly what it is called.
Thanks in advance.
I'm currently building a script of my own that categorizes articles for a blog.
I've got different categories, they're all stored within a single MYSQL table named 'categories', with three pieces of information each. id, title and parent. (ID is a primary key, title is the category name and parent is if this category is a sub category within another)
I've got the basic browsing sorted, using URL variables to move up and down the category levels, but the thing I can't work out, is how to display lower level categories articles. I have another table, 'articles' which contains this information 'id, title, content, category'
Obviously, when browsing the category tree, I can use a mysql_query to display articles marked with the same category as the one being viewed, but I can't find the lower level category articles with the ones within that category.
If I have these in my categories table:
id(3), title(Sample3), parent(0)
id(4), title(Sample4), parent(3)
id(5), title(Sample5), parent(3)
id(6), title(Sample6), parent(5)
So on the link article-list.php?cat=3, with the query I'm doing at the moment, it will show anything from sample4, and sample5, but I don't know how to include blog articles marked with category 6 aswell. Obviously, if I was only browsing category 5, it would show articles from that, and from category 6 too.
Have I structured my tables wrong to complete the task I'm trying to do? I know they're basic tables, but they're only for example. I would google this, if I knew exactly what it is called.
Thanks in advance.