Multi Level Kit


Writing a multi level kit routine, and am not sure of the best way to handle this in Coldfusion.

Hopefully you know what a multi level kit is, but if you dont it's just an item made up of other items, these items can be made up of other items etc, etc, etc.

So we need to start with one product loop through all the levels and return this information I was thinking of using structures or arrays or a combo, but not sure the best way of doing this.

All I need returned is a usable variable containing all the products and quantities.
LVL 18
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hello Pluka,
Well I am not sure if I have understood you correct but this is what we are doing at the moment. I though, I will give my opinion here may be that can be helpful.

We have one top level and they have siblings and we have their childs. Now it can be possible that Child have more kids and those kids can be parents of other child.... blah blah...
in short ... something like this....

1 ---> 2 ---->3
          | ---->4 ---->5
well the question is that this is bad design... may be ... but this is real life situation and we can do anything in our case... so let us accept that is what we have...

now... when we want to know the all the child of 1 ...

let us examine our database... it has field has
id, description, parent
1, something, 0
2, something, 1
3, something, 2
4, something, 2
like that....

so what we do is this...
we loop over all the id and see if they are child of anybody ...if not then they are parent id[1] and then move more down...and keep on adding them as list...(stupid as this is not greatly scalable but it is okey it works for us this is not major part just four level deep for us so we are good)
and find all teh child of that and we store them as variable.[1] =(2)
variable.[2] = (3,4) like that on wards...
now we know if we want to find how is child of whose this way and go on finding things using listcontains and all other list element... we also use listappend...

actually this was written year before and we are still using this without change.... may be this is not way you have asked but may be if this helps you ... I will be happy....

regarding using structs or array... actually they are the same...there is not differance... so whatever you use that is good... there is no effecient or better way as they are same for CF in all the way... IMHO.


that is how we know

>>> that is how we know

that is by error in previous msg i do not know when I wrote that...
show us the table structure, is it

product name
parent identity

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

there are many ways to retrieve this info, forget structure or arrays, just return it in a query...

What are you working with Access or MS SQL etc..?

The worst way, but probably the easiest is to retrieve all root level products first, i.e.

FROM yourTable
WHERE parentIdentity IS NULL

Loop over them, and on each itteration check the db if there is a record, i.e.


in a custom tags that traverses
FROM yourTable
WHERE identity = #parentIdentity#

END Loop

This is the easiest and most dirtiest way, the other way is to get the recordset from the db with info like depth for each record..
I will say I gave detailed answer even explaining the architecture. I will suggest asker to come back and respond.
PluckaAuthor Commented:
None of these are great solutions.

We ended up using Array of Structures.
The solution i offered is dirty as I said, but I'm pretty sure its better than the solution of arrays and structures?
Show us the solution you hvae, might be itneresting..

Also, I said
"the other way is to get the recordset from the db with info like depth for each record"
This is a whole lot more complicated and works with trees in the db, and definately better than any other solution, I did not eleborate on it because you did not seem interested.
PluckaAuthor Commented:
We used arrays of structures.

We have an array containing the items, each item is a structure detailing the components, each component can also be a kit thus the structure has an element defining the child as another array and so on and so on.

It is much better than the solution you proposed.
PAQed with points refunded (500)

Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.