How to create a dynamic tree similar to a structure

I have data about my family members in the database. I want to create a web page with a family tree dynamically generated by reading from a table.

My table schema looks like this:

id(int)  name  father(int)  mother(int)  spouse(int)  dateOfBirth

where father, motherand spouserefer to a column of idthe same table. The root root will be null for father and mother.

Given this data, how can I dynamically generate a family tree. I am new to the development of tables, so if this project is optimal, propose another scheme from which this goal can be achieved.

Any pointers on how to start from the beginning will be greatly appreciated.

+3
source share
3 answers

.

+2

, , .

. , , , ( :).

, (Child, Sibling, Spouse) -, , .

0

, , , , .

The best solution that I know (for hierarchical structures you have spouses) is to save the tree path in the row field. For example, you have a grandfather with id = 1, children with id = 2 and 3, 2 have children 4 and 5. Then they have paths respectively "," 1 "," 1 "," 1 "2", 1, 2 ".

You can use this structure to retrieve tree elements in order using a clause ORDER BY path.

0
source

All Articles