I'm creating a multi-level menu in php is pretty good but the problem arises when loading the sub-levels
<?php
$items = array(
array(
'idcategoria' => 1,
'nombre' => 'Pinturas',
'padre_id' => "0"
),
array(
'idcategoria' => 2,
'nombre' => 'Iluminacion',
'padre_id' => "0"
),
array(
'idcategoria' => 2,
'nombre' => 'Ilumssinacion',
'padre_id' => "1"
)
);
$id = "";
echo "<ul class='top-level-menu'>";
foreach ($items as $item) {
if ($item['padre_id'] == 0) {
echo "<li>" . $item['nombre'];
$id = $item['idcategoria'];
sub($items, $id);
echo "</li>";
}
}
echo "</ul>";
function sub($items, $id)
{
echo "<ul>";
foreach ($items as $item) {
if ($item['padre_id'] == $id) {
echo "<li class=''>" . $item['nombre'];
sub($item, $item['idcategoria']);
echo "</li>";
}
}
echo "</ul>";
}
?>
<style>
.third-level-menu{
position: absolute;
top: 0;
right: -150px;
width: 150px;
list-style: none;
padding: 0;
margin: 0;
display: none;
}
.third-level-menu > li
{
height: 30px;
background: #999999;
}
.third-level-menu > li:hover { background: #CCCCCC; }
.second-level-menu
{
position: absolute;
top: 30px;
left: 0;
width: 150px;
list-style: none;
padding: 0;
margin: 0;
display: none;
}
.second-level-menu > li
{
position: relative;
height: 30px;
background: #999999;
}
.second-level-menu > li:hover { background: #CCCCCC; }
.top-level-menu
{
list-style: none;
padding: 0;
margin: 0;
}
.top-level-menu > li
{
position: relative;
float: left;
height: 30px;
width: 150px;
background: #999999;
}
.top-level-menu > li:hover { background: #CCCCCC; }
.top-level-menu li:hover > ul
{
/* On hover, display the next level's menu */
display: inline;
}
/* Menu Link Styles */
.top-level-menu a /* Apply to all links inside the multi-level menu */
{
font: bold 14px Arial, Helvetica, sans-serif;
color: #FFFFFF;
text-decoration: none;
padding: 0 0 0 10px;
/* Make the link cover the entire list item-container */
display: block;
line-height: 30px;
}
.top-level-menu a:hover { color: #000000; }
</style>