Multilevel menu (PHP/MySQL)

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
sagstuen
Forum Newbie
Posts: 4
Joined: Sat Feb 07, 2004 3:36 pm

Multilevel menu (PHP/MySQL)

Post by sagstuen »

I'm doing a webshop project at the time. It's sort of a "learn-php-and-mysql"-project, meaning I'm not very into php yet...

What I'm having trouble figuring out is this...

I have a table in mysql whit the following fields:
group_id - INT PRIMARY AUTOINCREMENT
group_name VARCHAR(64)
group_parent - INT

To illustrate the table, let's say I have the following rows in the table:
1 - Hardware - 0
2 - Software - 0
3 - Motherboards - 1
4 - Network - 1
5 - Operatingsystems - 2
6 - Socket A - 3
7 - Socket 478 - 3
8 - Albatron - 6
9 - Albatron - 7
--->

The menu it self would be a tree view like this:
Hardware
- Motherboards
--- Socket A
----- Albatron
--- Socket 478
----- Albatron
- Network
Software
- Operatingsystems

Currently I've coded this by usinbg nested loops in a three-level arcitecture... Thats NOT what I want...
What I want is an unlimited level iterational loop, so I can put in the levels as it suits me and my needs.

My programming knowledge is farely simple at the time, so please make things a clear as possible...

Regards and thanks in advance...
Roger Jensen
Norway
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

i have done this thing upto 2 levels, Category and submeny with two while loops.
to do this multilevel thing you need to use recursion.
sagstuen
Forum Newbie
Posts: 4
Joined: Sat Feb 07, 2004 3:36 pm

SOLVED

Post by sagstuen »

Solved this one myself

See my posting in Code-Snippets
viewtopic.php?p=87015
Post Reply