i have attached the requirement.
1 register's from admin and it has some reference_id,
then,
2 reg with reference of 1 ref_id,
5 reg with reference of 2 ref_id

now my dout is i want to get the complete path i.e 1->2->5->9

Hello,

What you are referencing is often called a pyramid structure. I have built a few in the past and they can be interesting to code. However that being said the best method I have found to track the items is that every element has an id and a parent id. The parent id references the next unit up in the list. In your exsample there would be the following records:

ID parentId reference_notes
1 0 top of tree
2 1 element
3 1 second element
4 1 element
5 2 sub element
6 2 tree limb
7 4 sub element
8 4 sub element
9 5 sub element
10 5 another sub element
11 7 next level
12 7 next level

then you can track the items back up by starting at 9 and referencing up to 5 that references up to 2 and then 1.
Hope that helps.

thanks for your response db design is ok.can you give me business logic for this example if u have..pl

Member Avatar for diafol

ALthough I've used the "parent" structure in the past, I found it difficult to extract the data. A "simpler" method may be to use "nested sets" with "left" and "right" fields. Although simpler, it can cook your noodle to begin with. We can think of the "left" and "right" as a "start-point" and "end-point". I've got an example somewhere, I'll see if I can find it.

ok thank you ..try to send the business code if possible :).it can be done using phpmyadmin or i have to switch to oracle?

Member Avatar for diafol

Here's an example of the structure...

13038955c8a2eceffa80165f4e8349ae

5cb4b1f5df2f8dada72b4cd80df36795

d025cea1a7b6bc377d8685de9744a0b2

Member Avatar for diafol

UNfortunately I don't have my code with me, but I seem to remember that I built an xml document and used the "tab" character as an incrementer/decrementer. I'm sure there's an easier way. I'm pretty sure that there must a php class out there for this.

ok thank you...for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.