Hjælp med menu
Hej Eksperter,Jeg har følgende funktioner:
function setExpand($id, $level) {
if (!isset($_SESSION['expand']) && !is_array($_SESSION['expand'])) {
$_SESSION['expand'] = array();
}
if ($level == 0) {
unset($_SESSION['expand']);
$_SESSION['expand'] = array();
array_push($_SESSION['expand'],$id);
}
if (!in_array($id, $_SESSION['expand'])) {
array_push($_SESSION['expand'], $id);
}
return $_SESSION['expand'];
}
function getMenu($root=0) {
$parent = (int) $root;
$query = "SELECT id, gruppe, parentID, prioritet, parm FROM shopVaregrupper WHERE parentID = ".$parent." AND siteID = 1111111111 ORDER BY prioritet, gruppe";
$res = mysql_query($query) or die(mysql_error());
$self = array();
while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
$row['child'] = getMenu($row['id']);
$self[] = $row;
}
if (count($self) > 0) {
return $self;
} else {
return null;
}
}
function showMenu($struct, $level, $expand) {
$out = '';
if (is_array($struct) && count($struct)) {
if (isset($struct['id'])) {
$indent = '';
$indentHasSubs = '+';
for ($i=0;$i<$level;$i++) {
//$indent = '» ';
$indent = '---»';
}
if(is_array($struct['child'])) {
$out = $indent . $indentHasSubs. '<a href="?visGruppe='.$struct['id'].'">'.$struct['gruppe'].'</a>'.$level.'<br />';
} else {
$out = $indent . '<a href="?visGruppe='.$struct['id'].'">'.$struct['gruppe'].'</a>'.$level.'<br />';
}
if (is_array($struct['child']) && count($struct['child']) > 0) {
$level++;
foreach ($struct['child'] as $child) {
if(in_array($struct['id'], $expand)) {
$out .= $indent.showMenu($child,$level,$expand);
}
}
}
} else {
foreach ($struct as $root) {
$out .= showMenu($root,$level,$expand);
}
}
}
return $out;
}
De kaldes på følgende måde:
session_start();
include_once('../../../forbind.php');
empty($_GET['visGruppe']) ? $visGruppe = 0 : $visGruppe = $_GET['visGruppe'];
$getBreadcrumb = breadCrumb($visGruppe);
!isset($_SESSION['menuLevel']) ? $_SESSION['menuLevel'] = 0 : $_SESSION['menuLevel'] = count($getBreadcrumb)-1;
$exp = setExpand($visGruppe,$_SESSION['menuLevel']);
print showMenu(getMenu(),0, $exp);
--------------
Array'et jeg arbejder med ser således ud:
Array
(
[0] => Array
(
[id] => 199
[gruppe] => Test0
[parentID] => 0
[prioritet] => 0
[parm] =>
[child] => Array
(
[0] => Array
(
[id] => 200
[gruppe] => Test1
[parentID] => 199
[prioritet] => 0
[parm] =>
[child] => Array
(
[0] => Array
(
[id] => 201
[gruppe] => Test2
[parentID] => 200
[prioritet] => 0
[parm] =>
[child] => Array
(
[0] => Array
(
[id] => 202
[gruppe] => Test3
[parentID] => 201
[prioritet] => 0
[parm] =>
[child] =>
)
)
)
)
)
)
)
)
--------
Det jeg nu ikke kan forstå er, at min indrykning ikke virker længere end til level 2?
Herefter smider den blot punkterne under hinanden uden at rykke dem længere ud.
Kan nogen hjælpe?
