Nieuw lid |
|
Ik heb dit script:
<?php
$sqlConn = mysql_connect("localhost", "", "") or die("Couldn't connect to database");
$dbConn = mysql_select_db("", $sqlConn) or die("Couldn't connect to database");
$sql = "select * from nodes where parentId = 0 order by title asc";
$nodeResult = mysql_query($sql) or die("SELECT query failed");
$counter = 0;
?>
<ul>
<?php
while($node = mysql_fetch_array($nodeResult))
{
?>
<li><?php echo $node[1]; ?></li>
<li>
<ul>
<?php
$sql = "select * from nodes where parentId = {$node[0]} order by title asc";
@$childResult = mysql_query($sql);
while($child = mysql_fetch_row($childResult))
{
?>
<li><a href=""><?php echo $child[1]; ?></a></li>
<?php
}
?>
</ul>
</li>
<?php
}
?>
</ul>
<?php $sqlConn = mysql_connect("localhost", "", "") or die("Couldn't connect to database"); $sql = "select * from nodes where parentId = 0 order by title asc"; $counter = 0; ?> <ul> <?php { ?> <li> <?php echo $node[1]; ?></li> <li> <ul> <?php $sql = "select * from nodes where parentId = {$node[0]} order by title asc"; { ?> <li><a href=""> <?php echo $child[1]; ?></a></li> <?php } ?> </ul> </li> <?php } ?> </ul>
Deze tabel en gegevens:
CREATE TABLE `nodes` (
`nodeId` int(11) NOT NULL auto_increment,
`title` varchar(100) NOT NULL default '',
`url` varchar(250) default NULL,
`parentId` int(11) NOT NULL default '0',
PRIMARY KEY (`nodeId`),
UNIQUE KEY `id` (`nodeId`)
) TYPE=MyISAM AUTO_INCREMENT=13 ;
INSERT INTO `nodes` VALUES (1, '1', '', 0);
INSERT INTO `nodes` VALUES (2, '2', '', 0);
INSERT INTO `nodes` VALUES (3, '3', '', 0);
INSERT INTO `nodes` VALUES (4, '1.1', '', 1);
INSERT INTO `nodes` VALUES (5, '1.2', '', 1);
INSERT INTO `nodes` VALUES (6, '1.3', '', 1);
INSERT INTO `nodes` VALUES (7, '2.1', '', 2);
INSERT INTO `nodes` VALUES (8, '2.2', '', 2);
INSERT INTO `nodes` VALUES (9, '2.3', '', 2);
INSERT INTO `nodes` VALUES (10, '3.1', '', 3);
INSERT INTO `nodes` VALUES (11, '3.2', '', 3);
INSERT INTO `nodes` VALUES (12, '1.1.1', '', 4);
CREATE TABLE `nodes` ( `nodeId` int(11) NOT NULL auto_increment, `title` varchar(100) NOT NULL default '', `url` varchar(250) default NULL, `parentId` int(11) NOT NULL default '0', UNIQUE KEY `id` (`nodeId` )) TYPE=MyISAM AUTO_INCREMENT=13 ; INSERT INTO `nodes` VALUES (1, '1', '', 0); INSERT INTO `nodes` VALUES (2, '2', '', 0); INSERT INTO `nodes` VALUES (3, '3', '', 0); INSERT INTO `nodes` VALUES (4, '1.1', '', 1); INSERT INTO `nodes` VALUES (5, '1.2', '', 1); INSERT INTO `nodes` VALUES (6, '1.3', '', 1); INSERT INTO `nodes` VALUES (7, '2.1', '', 2); INSERT INTO `nodes` VALUES (8, '2.2', '', 2); INSERT INTO `nodes` VALUES (9, '2.3', '', 2); INSERT INTO `nodes` VALUES (10, '3.1', '', 3); INSERT INTO `nodes` VALUES (11, '3.2', '', 3); INSERT INTO `nodes` VALUES (12, '1.1.1', '', 4);
En wil nu in het menu 1.1 nog een subemenu met de naam 1.1.1
Wie kan me hierbij helpen, misschien zou het zelfs een recursieve functie moeten worden maar heb geen idee hoe dat zou moeten.
|