Created
November 10, 2011 16:03
-
-
Save abidibo/1355210 to your computer and use it in GitHub Desktop.
Recursion to get a tree from a id-parent sql table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// I use here Jeff's db methods | |
public function getTree($registry, $parent=0) { | |
$child_rows = $registry->db->autoSelect("id", TABLE, "parent='$parent'", "name"); | |
$children = array(); | |
foreach($child_rows as $row) { | |
$children[$row['id']] = self::getTree($registry, $row['id']); | |
} | |
return $children; | |
} | |
?> |
Since this snippet is used to retrieve a menu tree, this is not the case
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so if there are 100 child rows, you recursively make 100 SQL queries?