Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Multi Level Kit

Posted on 2004-10-24
12
Medium Priority
?
235 Views
Last Modified: 2013-12-24
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
Comment
Question by:Plucka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
12 Comments
 
LVL 21

Expert Comment

by:pinaldave
ID: 12397559
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 21

Expert Comment

by:pinaldave
ID: 12397560
>>> 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

by:Tacobell777
ID: 12479480
show us the table structure, is it

identity
product name
parent identity

???
0
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 
LVL 17

Expert Comment

by:Tacobell777
ID: 12479493
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 21

Expert Comment

by:pinaldave
ID: 12718179
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

by:Plucka
ID: 12741874
None of these are great solutions.

We ended up using Array of Structures.
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 12813052
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

by:Plucka
ID: 12815435
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

by:Tacobell777
ID: 12815554
ok
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12848507
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question