Solved

# Multi Level Kit

Posted on 2004-10-24
192 Views
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
Question by:Plucka

LVL 22

Expert Comment

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

LVL 22

Expert Comment

>>> that is how we know

that is by error in previous msg i do not know when I wrote that...
---Pinal
0

LVL 17

Expert Comment

show us the table structure, is it

identity
product name
parent identity

???
0

LVL 17

Expert Comment

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

LVL 22

Expert Comment

I will say I gave detailed answer even explaining the architecture. I will suggest asker to come back and respond.
0

LVL 18

Author Comment

None of these are great solutions.

We ended up using Array of Structures.
0

LVL 17

Expert Comment

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

LVL 18

Author Comment

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

LVL 17

Expert Comment

ok
0

Accepted Solution

PAQed with points refunded (500)

modulo
Community Support Moderator
0

## Featured Post

### Suggested Solutions

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
This video discusses moving either the default database or any database to a new volume.