PhpRiot
Download This Article
Download this article or the entire “Implementing An N-Level Nested Tree In PHP And PostgreSQL” series with all listings and files.




More information
Related Books
Professional Linux Programming

Professional Linux Programming

As Linux increases its presence throughout the world as a target platform for professional...
Browse Articles
Ajax (4), APC (1), CAPTCHA (1), CSS (3), Debugging (1), File Upload (1), Google (3), Google Maps (2), JavaScript (12), JSON (2), MVC (1), MySQL (7), onbeforeunload (1), OOP (1), PHP (28), PhpDoc (1), PostgreSQL (6), Prototype (11), Reflection (1), RFC 1867 (1), Robots (1), Scriptaculous (1), SEO (1), Sessions (1), SimpleXML (1), Smarty (5), SOAP (1), SPL (1), Templates (2), W3C (1), XHTML (1), Zend Framework (1), Zend_Search_Lucene (1)

PhpRiot Newsletter
Your Email Address:

Implementing An N-Level Nested Tree In PHP And PostgreSQL, Part 1

A Sample Nested Tree

This web site uses a nested tree to structure the documents and the relationships between the documents. We refer to each document as a node. At time of writing, part of the PhpRiot nested was structured as such:

Listing 1 A Sample Nested Tree (listing-1.txt)
Title
------------------------
General Resources
   Code Paste
   Documentation
   Books & Publications
      Apache
      PostgreSQL
      MySQL
   Links
      Databases
      Generators
      Portals

Just by looking at this structure, we can determine the following information:

  • The section is called General Resources, and has the children Code Paste, Documentation, Books & Publications and Links.
  • Documentation has three siblings: Code Paste, Books & Publications and Links
  • PostgreSQL has parent Books & Publications, and is an ancestor of General Resources
  • Portals is a descendants of General Resources.

Obviously there is much more that can be determined, but this hopefully demonstrates the point.

Although we refer to each item as a node, beacuse it’s a tree structure you could also use the following terminology:

  • A nodes with no children is a leaf
  • A node with children is a branch

In This Article


Tagged in , ,