CodeIgniter Forums
Dealing with parents and children in databases - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Dealing with parents and children in databases (/showthread.php?tid=2102)



Dealing with parents and children in databases - El Forum - 07-16-2007

[eluser]zscott[/eluser]
Hi,
I have a single table database structure that I'm trying to manage through PHP. Each record is a container that could have other records within it. So there is an auto-incrementing id for the record that is associated to sub records via the parentid column. Essentially 1 record could have 1 child that has children that has many children, and I need a way to find all them kids and kill em.

Does anyone have any ideas/ways I could do this with some PHP magic?

Please help :down:


Dealing with parents and children in databases - El Forum - 07-16-2007

[eluser]esra[/eluser]
I believe you're describing the Adjacency List Model where recursion is used to handle hierarchies of data. See if this article helps:

http://www.sitepoint.com/article/hierarchical-data-database

The other approach to managing hierachies mentioned in the article is the nested sets model. Thunder has posted a nice model and sample application on the wiki:

http://codeigniter.com/wiki/Nested_sets/

There are advantages and disadvantages of using both models.


Dealing with parents and children in databases - El Forum - 07-16-2007

[eluser]zscott[/eluser]
That's exactly what I was looking for!!!
Thanks a bunch Big Grin