0

How do i keep track of parents and children?

I want to know how many children I have, and how many grandchildren I have, and then, also how many grand-grand-children i have, and finally, how many grand-grand-grand-children I have.

The table is simple, where every person has an TINYINT which identifies whom the (single) parent is, e.g. I can see that MY parent is "123". My own id is "345", so my children will each have their "parent" set to "345".

So every person has an "id", and a "parent", both TINYINTs.

I want a PHP line to echo "You parent is "John" and his number is "123". You have X children, X grandchildren, X g-grandchildren, and X g-g-grandchildren."

Much appreciated!

  • Hello, can you please show us what you have done so far ? – YounesM Mar 16 '17 at 09:16
  • im a complete noob, so i dont even know where to begin – Neinja MCSquare Mar 16 '17 at 11:46
  • Check out this article on [Managing Hierarchical Data in MySQL](http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/). – showdev Mar 16 '17 at 17:09
  • Possible duplicate of [How to create a MySQL hierarchical recursive query](http://stackoverflow.com/questions/20215744/how-to-create-a-mysql-hierarchical-recursive-query) – showdev Mar 16 '17 at 17:11

0 Answers0