Page 1 of 1
database tree php
Posted: Tue Oct 05, 2004 6:41 am
by CreativeForce
i have this database which is fairly simple:
id id_numeric
1 0
2 1
3 1
4 0
5 3
6 3
7 5
8 0
9 7
i wish to print out this(a tree):
1 0
2 1
3 1
5 3
7 5
9 7
6 3
4 0
8 0
0 means that they are root. i'm not sure how to start. do i make them to arrays or do i loop. i don't know so i would really appreciate your help here.

Posted: Tue Oct 05, 2004 6:54 am
by twigletmac
I can't see a particular pattern to the output? By a tree what exactly do you mean?
Mac
Posted: Tue Oct 05, 2004 7:37 am
by Weirdan
pattern is perhaps:
Code: Select all
1 0
2 1
3 1
5 3
7 5
9 7
6 3
4 0
8 0
Posted: Tue Oct 05, 2004 7:45 am
by twigletmac
Aah - just looks like numbers when it's put in a straight line. So it's recursion that's needed - maybe this will help:
http://www.sitepoint.com/article/hierar ... a-database
Mac
Posted: Tue Oct 05, 2004 8:55 am
by CreativeForce
any other alternative to that. i'm thinking arrays. but i don't know how.
Posted: Tue Oct 05, 2004 9:08 am
by twigletmac
Did you have a go at the code in the SitePoint article - it had a bunch of code you could make a start on? Basically you're going to need a recursive function - one that calls itself - in order to generate the tree of parents and children.
Mac
Posted: Tue Oct 05, 2004 10:33 am
by feyd