T
Tore Aursand
Hi!
Like all other web sites, my homepage needs a menu. I've come to a
decision where I want to be able to link "all pages to all the other
pages", ie. a hierarchial structure where a child can have multiple
parents.
Everything is store inside a database, and here's the data structure,
where each item in the menu is a 'section' (as MySQL);
section
-------
section_id int unsigned auto_increment primary key,
title varchar(80) not null
section_parent
--------------
section_id int unsigned not null,
parent_id int unsigned not null,
position int unsigned not null
The 'position' field denotes the - right - position of the section
relative to its parent.
What I need is a function to gather the data about all the sections, what
"level" they are on etc., so that it's as easy as possible for me to
output the menu;
my $stSections = $dbh->prepare('SELECT s.section_id, s.title,
sp.parent_id, sp.position
FROM section s, section_parent sp
ORDER BY sp.parent_id, sp.position');
$stSections->execute();
while ( my @section = $stSections->fetchrow_array() ) {
my $section_id = $section[0];
my $title = $section[1];
my $parent_id = $section[2];
my $position = $section[3];
}
$stSections->finish();
How should I really proceed from here? What's the best way? I'm not sure
what to try from here...?
Thanks again for all help!
--
Tore Aursand <[email protected]>
"Anyone who slaps a 'this page is best viewed with Browser X'-label on
a web page appears to be yearning for the bad old days, before the
web, when you had very little chance of reading a document written on
another computer, another word processor or another network." -- Tim
Berners-Lee, July 1996
Like all other web sites, my homepage needs a menu. I've come to a
decision where I want to be able to link "all pages to all the other
pages", ie. a hierarchial structure where a child can have multiple
parents.
Everything is store inside a database, and here's the data structure,
where each item in the menu is a 'section' (as MySQL);
section
-------
section_id int unsigned auto_increment primary key,
title varchar(80) not null
section_parent
--------------
section_id int unsigned not null,
parent_id int unsigned not null,
position int unsigned not null
The 'position' field denotes the - right - position of the section
relative to its parent.
What I need is a function to gather the data about all the sections, what
"level" they are on etc., so that it's as easy as possible for me to
output the menu;
my $stSections = $dbh->prepare('SELECT s.section_id, s.title,
sp.parent_id, sp.position
FROM section s, section_parent sp
ORDER BY sp.parent_id, sp.position');
$stSections->execute();
while ( my @section = $stSections->fetchrow_array() ) {
my $section_id = $section[0];
my $title = $section[1];
my $parent_id = $section[2];
my $position = $section[3];
}
$stSections->finish();
How should I really proceed from here? What's the best way? I'm not sure
what to try from here...?
Thanks again for all help!
--
Tore Aursand <[email protected]>
"Anyone who slaps a 'this page is best viewed with Browser X'-label on
a web page appears to be yearning for the bad old days, before the
web, when you had very little chance of reading a document written on
another computer, another word processor or another network." -- Tim
Berners-Lee, July 1996