[PHP-DB] Re: MySQL/PHP Iterative Tree
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Greetings John On 26 November 2002 at 18:54:04 -0500 (which was 23:54 where I live) John W. Holmes wrote and made these points This is OK for some simple trees, however it does have some limitations. (1) Adding another tree / series of nodes into the middle if the set. Not if you can define what the absolute max size of a node will be. Most of my applications I can not, and this is a limitation that I would never want to impose on on my apps. If you can then good. (2) A child node that belongs to more than one parent. I give a certain company the node numbers of 6-5006. Now assign that left and right pair a unique id. Now you can have multiple people with that same ID. I might have misunderstood you but sorry but this is a big no no in my all my apps. Every item must have a unique ID. This is a fundamental basis of all my systems. - -- See you in Cyber space, ___ David |David Elliott| Software Engineer| _| [EMAIL PROTECTED] | PGP Key ID 0x650F4534 | | Would it help if I got out and pushed? -Princess Leia | -BEGIN PGP SIGNATURE- Version: 6.5.8ckt http://www.ipgpp.com/ iQA/AwUBPeSW6PmK8eZlD0U0EQJ+HwCg4UQSEN5ee3i5kUiiM7aBsDH0cl4AmwbM /l5gv6cPCULmf9KUWJ46LY2a =4Hwb -END PGP SIGNATURE- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: MySQL/PHP Iterative Tree
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello Adam On 26 November 2002 at 08:25:22 -0500 (which was 13:25 where I live) Adam Voigt emanated these words of wisdom ... Ok, and I am using this structure to make a kind of drill down structure, so the top level would be where parentid = '0', then you take those id's and select from this table where parentid is equal to those id's, and now your starting to navigate through the tree, and so on. Now, the real question, I have found a Javascript menu script which will let users of the site click on it, and then click on the submenu and down and down through all the level's that might dynamically exist, Be careful of the size and the time it takes to build a big tree. but I can't for the life of me figure out how to recursively get the name and id for each row (which is what I need to build the menu and make link's out of each item), for as many sublevel's as there might be (infinite). Am I missing something, is there a simple logical way to do this recursively? Or if there's a semi-complex way, anyone got a script example? I'd very much appreciate it. This is not much help but have done something like that in MSSQL with stored procedure (about 120 to 150 lines of SQL). The logic went something like. get all top level put into a temptable_1 go through temptable_1 put line into temptable_2 noting level add on any children for line into temptable_2 next line of temptable_1 copy temptable_2 to temptable_1 keep going through temptable_1 until there is no more children at last level I also used a separate table for the links this way it is easier to go both up and down the tree. What would be nice is to do it dynamically and display only the tree that you need and just get the data for the children when needed. eg like MSDSon M$ site - -- TTFN, ___ David |David Elliott| Software Engineer| _| [EMAIL PROTECTED] | PGP Key ID 0x650F4534 | | I am Barney of Borg...Sesame Street will be assimilated.| -BEGIN PGP SIGNATURE- Version: 6.5.8ckt http://www.ipgpp.com/ iQA/AwUBPeOIC/mK8eZlD0U0EQI8YQCdEKtpYBkVNmLGYEs2xt3RKBoh1A0An2FG KzmAxhrABe/7JZxw3mvmYkaJ =xdTm -END PGP SIGNATURE- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: MySQL/PHP Iterative Tree
You may want to check out using Nested Sets instead of a Parent-Child-ID system. I think it's an easier system for representing hierarchies. Here is a good article on the system: http://searchdatabase.techtarget.com/tip/1,289483,sid13_gci537290,00.html Google for Nested Sets +sql or something and there are more articles out there. It's sort of confusing in the beginning. If you have any questions, let's take it off the PHP list. ---John Holmes... - Original Message - From: David Elliott [EMAIL PROTECTED] To: Adam Voigt on PHP-DB [EMAIL PROTECTED] Sent: Tuesday, November 26, 2002 9:41 AM Subject: [PHP-DB] Re: MySQL/PHP Iterative Tree -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello Adam On 26 November 2002 at 08:25:22 -0500 (which was 13:25 where I live) Adam Voigt emanated these words of wisdom ... Ok, and I am using this structure to make a kind of drill down structure, so the top level would be where parentid = '0', then you take those id's and select from this table where parentid is equal to those id's, and now your starting to navigate through the tree, and so on. Now, the real question, I have found a Javascript menu script which will let users of the site click on it, and then click on the submenu and down and down through all the level's that might dynamically exist, Be careful of the size and the time it takes to build a big tree. but I can't for the life of me figure out how to recursively get the name and id for each row (which is what I need to build the menu and make link's out of each item), for as many sublevel's as there might be (infinite). Am I missing something, is there a simple logical way to do this recursively? Or if there's a semi-complex way, anyone got a script example? I'd very much appreciate it. This is not much help but have done something like that in MSSQL with stored procedure (about 120 to 150 lines of SQL). The logic went something like. get all top level put into a temptable_1 go through temptable_1 put line into temptable_2 noting level add on any children for line into temptable_2 next line of temptable_1 copy temptable_2 to temptable_1 keep going through temptable_1 until there is no more children at last level I also used a separate table for the links this way it is easier to go both up and down the tree. What would be nice is to do it dynamically and display only the tree that you need and just get the data for the children when needed. eg like MSDSon M$ site - -- TTFN, ___ David |David Elliott| Software Engineer | _| [EMAIL PROTECTED] | PGP Key ID 0x650F4534 | | I am Barney of Borg...Sesame Street will be assimilated. | -BEGIN PGP SIGNATURE- Version: 6.5.8ckt http://www.ipgpp.com/ iQA/AwUBPeOIC/mK8eZlD0U0EQI8YQCdEKtpYBkVNmLGYEs2xt3RKBoh1A0An2FG KzmAxhrABe/7JZxw3mvmYkaJ =xdTm -END PGP SIGNATURE- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: MySQL/PHP Iterative Tree
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello 1LT On 26 November 2002 at 09:54:57 -0500 (which was 14:54 where I live) 1LT John W. Holmes emanated these words of wisdom You may want to check out using Nested Sets instead of a Parent-Child-ID system. This is OK for some simple trees, however it does have some limitations. (1) Adding another tree / series of nodes into the middle if the set. (2) A child node that belongs to more than one parent. - -- Cheers, ___ David |David Elliott| Software Engineer| _| [EMAIL PROTECTED] | PGP Key ID 0x650F4534 | | Mathematicians DO IT with sum. | -BEGIN PGP SIGNATURE- Version: 6.5.8ckt http://www.ipgpp.com/ iQA/AwUBPeOcYPmK8eZlD0U0EQJRVACfXZGjwwUlKOV1yEvtEf96D0MdNakAnAuF PBlwh2HSenDKSVvldLp8H3fb =QE8q -END PGP SIGNATURE- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: MySQL/PHP Iterative Tree
A coworker suggested I just write either the array or the actual menu itself (in a .js file) at the time of category/subcategory creation and just include it on the page with the menu, which I suppose is what I must do since most other on-the-fly solutions seem fairly complicated and can get exponentially resource intensive. Thanks for your help. On Tue, 2002-11-26 at 11:07, David Elliott wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello 1LT On 26 November 2002 at 09:54:57 -0500 (which was 14:54 where I live) 1LT John W. Holmes emanated these words of wisdom You may want to check out using Nested Sets instead of a Parent-Child-ID system. This is OK for some simple trees, however it does have some limitations. (1) Adding another tree / series of nodes into the middle if the set. (2) A child node that belongs to more than one parent. - -- Cheers, ___ David |David Elliott| Software Engineer| _| [EMAIL PROTECTED] | PGP Key ID 0x650F4534 | | Mathematicians DO IT with sum. | -BEGIN PGP SIGNATURE- Version: 6.5.8ckt http://www.ipgpp.com/ iQA/AwUBPeOcYPmK8eZlD0U0EQJRVACfXZGjwwUlKOV1yEvtEf96D0MdNakAnAuF PBlwh2HSenDKSVvldLp8H3fb =QE8q -END PGP SIGNATURE- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Adam Voigt ([EMAIL PROTECTED]) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc signature.asc Description: This is a digitally signed message part
[PHP-DB] RE: MySQL/PHP Iterative Tree
You may want to check out using Nested Sets instead of a Parent-Child-ID system. This is OK for some simple trees, however it does have some limitations. (1) Adding another tree / series of nodes into the middle if the set. Not if you can define what the absolute max size of a node will be. I've been looking to using this for the military, to represent the chain of command. The structure of the military would be like this: 1)Army, 2)Corp, 3)Division, 4)Brigade, 5)Battalion, 6)Company, 7)Platoon, 8)Squad, 9)Individual So I define a squad to have 50 elements, a platoon to have 10 squads, a company to have 10 platoons. Normally, these would have a lot less than that, but I've built in some extra space. So if I create a company, it gets node number of 6-5006. (Company is number 6 above, this allows you to add nodes above this one, also, that contain this one) So it has 5000 spaces in it. The first platoon would have node number of 7-507. First squad has 8-58. So to add in another platoon, simply select the max number under the company you want to add it to. In this case, it would be 507. So, even with data already there, the next platoon added would have node number of 508-1008. You can still do all of the regular nest set queries, too. (2) A child node that belongs to more than one parent. Again, not really. In the above example, I give a certain company the node numbers of 6-5006. Now assign that left and right pair a unique id. Now you can have multiple people with that same ID. So you can have 3 managers at the same level, associated with the same unique id and left right pair, and be in charge of the same people. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php