Нужно построить дерево, вот только не пойму как вернуться на верхний уровень (Спасибо всем) function search_childe($node) { $query2 = 'select * from itemrangetable where ParentId = "'.$node.'" Group By menuitemid'; $this -> result2 = mysql_query($query2) or die ('ОШИБКА !!!'); while ( $num = mysql_fetch_array( $this -> result2 ) ) { print($num['MenuItemId'].'<br />'); $this -> search_childe($num['MenuItemId']); } } function run() { $query = 'select * from menuitemtable join itemrangetable on ItemId = MenuItemId where ParentId = "" and ItemId ="Producer"'; $this -> result = mysql_query($query) or die ('ОШИБКА !!!'); while ( $num = mysql_fetch_array( $this -> result ) ) { $this -> itemid = $num['ItemId']; $this -> search_childe($num['ItemId']); } }