Forum Moderators: coopster

Message Too Old, No Replies

Unlimited levels and subcats

         

netfiends

4:28 am on Jan 5, 2007 (gmt 0)

10+ Year Member



I've tried figuring this out once before but gave up and now I need to figure it out again :sigh:. I want to offer my users unlimited levels and subcategories but cannot figure out how to pull them so they go into the right parent cat. I know how to pull them just not unlimited levels deep.

-Matt

eelixduppy

4:33 am on Jan 5, 2007 (gmt 0)




I want to offer my users unlimited levels and subcategories but cannot figure out how to pull them so they go into the right parent cat. I know how to pull them just not unlimited levels deep.

All of this is a little vague. Do you think you could elaborate on your idea a little as to help us help you the best we can? ;)

Aside from telling us what you want to do, could you define a subcategory, too? Unless you are meaning a subdirectory?

phranque

4:47 am on Jan 5, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



do you mean how to find the url to navigate to the parent category?
how is your content organized?

jatar_k

4:57 am on Jan 5, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



yo make it truly unlimited I would imagine that, at some point, you will need a loopback to a higher cat

you could use a 'related' schema on top of the standard parent child type

when you run out of children then start working on related, as long as each major cat has 2 or more related cats then it should appear infinite

netfiends

7:04 am on Jan 5, 2007 (gmt 0)

10+ Year Member



"All of this is a little vague. Do you think you could elaborate on your idea a little as to help us help you the best we can? ;)

Aside from telling us what you want to do, could you define a subcategory, too? Unless you are meaning a subdirectory?" -- I meant subcategory. Example: Cars [Main category]: Honda [sub category]: Civic [sub category of a parent category]: 2DR [sub category]. I don't think it's termed as subdirectories because they aren't actual files, just navigation links. With that said I want my users to be able to add the main category [cars] and unlimited sub categories unlimited levels deep [car types, models, body types, etc...].

"do you mean how to find the url to navigate to the parent category?
how is your content organized?" -- I don't really need to find the URL rather just a way to display all of the categories under their right parent; I can do that right now but not unlimited levels deep.

"yo make it truly unlimited I would imagine that, at some point, you will need a loopback to a higher cat

you could use a 'related' schema on top of the standard parent child type

when you run out of children then start working on related, as long as each major cat has 2 or more related cats then it should appear infinite" -- A loop, function whatever would be fine; I just can't wrap my mind about how to check EVERY category for it a child then check every child for a child, etc... I'm not sure what you mean by "related schema"? I have all of my categories stored in my DB,

id, name, parent, main_category [contains "main" when the category is a main category or contains the main category for children categories]. I don't even know if this can be done but figured I'd ask around before limiting my users to a set amount of categories.

phranque

10:07 am on Jan 5, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



a lot depends on how well you kow data structures, what tools you have available and how efficient it needs to be.
for example you could build a tree structure from your category data and then navigate that to display all the categories.
since you are allowing unlimited levels you will have to come up with some kind of recursive solution while protecting yourself from infinite recursion.
start by simplifying the problem:
- each item in the tree is a node
- every node is a branch (has subcategories) or a leaf (represents some actual content)
- start with the root node and iterate on its sub nodes
- for each node, either recurse on branch processing or finish your leaf processing and move on to the next node on the parent branch.

jatar_k

2:39 pm on Jan 5, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> for each node, either recurse on branch processing or finish your leaf processing and move on to the next node on the parent branch.

this is pretty much the 'related' premise

at some point the branch ends, therefore you need to create points higher up that you can use to select other branches that are closely related to the topic/cat/search your user is doing

this would mean that no branch ends because it is connected at it's end to at least one other branch, creating the illusion of unlimited

no matter what you do there will only ever be a finite number of cats, at some point the user will see something they have seen before

phranque has a good explanation of the basics there

phranque

10:27 pm on Jan 5, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



to restate some of what has been said in case it wasn't obvious enough, you should keep a list of the nodes you have processed, so you don't reprocess if it recurs elsewhere in the tree.

another simple way to limit recursion problems is to only provided a finite number of levels of nevigation at each node. (i.e. the tree structure can be recursive but you have to navigate to see past n levels.)

netfiends

9:49 am on Jan 9, 2007 (gmt 0)

10+ Year Member



I'm searching for the most efficient way possible. Would it be more efficient to recurse the categories as they're pulled or put them in an array and go through them that way? I'm still lost on recursion so any examples, tips, whatever would be appreciated. Thanks all.