PhpRiot
Follow phpriot on Twitter
Sponsored Link
Download 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
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store
Free iPad/iPhone App
Available on the App Store

  • PHP manual
  • Zend Framework manual
  • Smarty manual
  • PHP articles
  • PHP training

Related Books
PHP 5 Advanced: Visual QuickPro Guide

PHP 5 Advanced: Visual QuickPro Guide

Sharpen your PHP skills with the fully revised and updated, PHP 5 Advanced for the World Wide...

Foundations of CentOS Linux

Foundations of CentOS Linux

This will be the book introducing CentOS servers and how to add and manage Fedora clients, with...

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