• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

Multi Level Kit

Hi,

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.
0
Plucka
Asked:
Plucka
  • 4
  • 3
  • 2
  • +1
1 Solution
 
pinaldaveCommented:
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
                    |
                    |---->6---->2
                   
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.

Regards,
---Pinal

that is how we know

0
 
pinaldaveCommented:
>>> that is how we know

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

identity
product name
parent identity

???
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Tacobell777Commented:
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.

SELECT *
FROM yourTable
WHERE parentIdentity IS NULL

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

BEGIN Loop

in a custom tags that traverses
<cfquery>
SELECT *
FROM yourTable
WHERE identity = #parentIdentity#
</cfquery>

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..
0
 
pinaldaveCommented:
I will say I gave detailed answer even explaining the architecture. I will suggest asker to come back and respond.
0
 
PluckaAuthor Commented:
None of these are great solutions.

We ended up using Array of Structures.
0
 
Tacobell777Commented:
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.
0
 
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.
0
 
Tacobell777Commented:
ok
0
 
moduloCommented:
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now