我有一个需要从数据库动态创建的菜单。需要有菜单和子菜单
<?php
$sql =('SELECT rubriques.id,rubriques.intitule,actions.intitulee,actions.lien,actions.idr FROM rubriques,actions where rubriques.id=actions.idr ');
$stmt = $conn->query($sql);
if($stmt->num_rows > 0)
{
while($row=$stmt->fetch_assoc())
{
extract($row);
?>
<li class="active"><a href="index.html"><?php echo $intitule; ?></a>
<ul class="dropdown">
<li><a href="<?php echo $lien; ?>"><?php echo $intitulee; ?></a></li>
</ul>
<?php
} }
?>
例如(我想要什么):
如果 A 是菜单项而 A1 A2 A3 是子菜单项我想要的是这样的菜单 A
A1
A2
A3
但我得到的这段代码是
AAA
A1 A2 A3
```CREATE TABLE IF NOT EXISTS `actions` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`intitulee` varchar(255) NOT NULL,
`lien` varchar(255) NOT NULL,
`idr` int(255) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ;
INSERT INTO `actions` (`id`, `intitulee`, `lien`, `idr`) VALUES
(1, 'Estivage', 'estirage.php', 1),
(4, 'Excursions', 'exurcions.html', 1),
(5, 'Equipe foot', '404.html', 2),
(6, 'Clubs de sports ', '404.html', 0),
(7, 'Fete des femmes', '404.html', 3),
CREATE TABLE IF NOT EXISTS `rubriques` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`intitule` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
INSERT INTO `rubriques` (`id`, `intitule`) VALUES
(1, 'Voyages'),
(2, 'ACTIVITES CULTURELLES ET SPORTIVES.'),
(3, 'FETES & RECEPTIONS'),
偶然的你
幕布斯6054654
慕田峪9158850