Page 1 of 1

Multilevel menu (PHP/MySQL)

Posted: Sat Feb 07, 2004 4:05 pm
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

Posted: Sun Feb 08, 2004 12:33 am
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.

SOLVED

Posted: Sun Feb 08, 2004 7:01 pm
by sagstuen
Solved this one myself

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