Creating a multi-dimensional array from MySQL table
Posted: Fri Aug 19, 2005 8:09 am
Hi, I need to create a multi-dimensional array from a database table for a navigation tree system.
nav_id is the ID of the navigation item
nav_parent is the ID of the navigation item which is the current nav items parent (if that makes sense? :p)
That is the table format.
I need to output it to build a navigation tree like this;
Item1
-Item2
--Item3
--Item4
--Item5
---Item6
--Item7
-Item8
-Item9
Item10
Item11
-Item12
and so on.
Only managed to get 2 level array right so far. Any help is much appreciated.
Code: Select all
CREATE TABLE `navigation` (
`nav_id` int(11) NOT NULL auto_increment,
`nav_parent` int(11) NOT NULL default '0',
`nav_label` varchar(50) NOT NULL default '',
`nav_href` varchar(255) NOT NULL default '',
`nav_position` int(11) NOT NULL default '0',
PRIMARY KEY (`nav_id`)
) TYPE=MyISAM;nav_parent is the ID of the navigation item which is the current nav items parent (if that makes sense? :p)
That is the table format.
I need to output it to build a navigation tree like this;
Item1
-Item2
--Item3
--Item4
--Item5
---Item6
--Item7
-Item8
-Item9
Item10
Item11
-Item12
and so on.
Only managed to get 2 level array right so far. Any help is much appreciated.