News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPBuilder.com:
Handling Hierarchical Data in MySQL and PHP
September 06, 2012 @ 10:16:44

On PHPBuilder.com today there's a new tutorial showing you a way to work with hierarchical data in MySQL from your PHP application in two different ways (methods).

The hierarchical data structure is one of the most common data structures in programming. It represents a set of data where each item (except the root) has one parent node and one or more children nodes. Web programmers use hierarchical data for a number of applications, including content management systems, forum threads, mailing lists, and e-commerce product categorization. In this tutorial , I will explain how to manage hierarchical data using MySQL and PHP. Specifically, I will explore the two most popular hierarchical data models: adjacency list model and nested set model.

They start with the adjacency list model, showing how to do a left join on the table on the parent ID to record ID and then filter through them, merging them into a main array as needed. The nested set model is slightly different and involves two new columns, a "lft" and "rgt", that point you to the records around the current one. This method makes the actual SQL query to find the structure a bit simpler, but isn't quite as flexible as the first method.

0 comments voice your opinion now!
hierarchical data mysql tutorial nestedset adjacencylist


blog comments powered by Disqus

Similar Posts

Fabien Potencier's Blog: Create your own framework...on top of the Symfony2 Components (parts 3 & 4)

Sameer Borate's Blog: Google Translation PHP wrapper

DZone.com: MySQL PHP search: four-part video tutorial series

Matthew Weier O'Phinney's Blog: Rendering Zend_Form decorators individually

MelonFire Community: Caching Web Sites With PEAR Cache


Community Events





Don't see your event here?
Let us know!


laravel opinion interview introduction update podcast deployment library community series zendserver api framework release install language tips package symfony list

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework