----- Original Message ----- From: "Richard Unitek" richardc@unitek.co.in To: "GNU/Linux Users Group, Mumbai, India" linuxers@mm.ilug-bom.org.in Sent: Wednesday, June 04, 2003 4:05 PM Subject: [ILUG-BOM] [OT] PHP - building/simulating tree structure.
Hi
This is an off topic posting.
I want to build a multi level tree system using php and database like
mysql.
Firstly, note that it's PHP and MySQL. OK, I can see you want to use _databases_ and I assume you want trees to make categories and subcategories.... that support as many as levels you want.
Well, you'd do it this way: 1. Every node/leaf has to be identifiable, so every node/leaf will have to have an ID.
2. Nodes/leaves other than the root will be children of someone... so there must be some mechanism to identify the parent. Use the Parent's ID...
In database talk, you'd use a table with two keys... one primary and a foreign. The foreign key will refer the parent key of it's own table.
There are obviously better ways of doing this, but everything depends on where you want to apply the code. Let me know if you need further help _off-list_.
And oh yes, there is alreay a lot of code that does things like this. One can learn a lot by just looking at existing code rather than posting at lists in panic mode.
Regards,
ah.