Forum Moderators: coopster
class CMStree extends DbConnector{ var $fullNav; // Compile full navigation to return once all data obtained function ShowPageTree($parent, $level, $item = 0, $theUL){ // Check if we're opening a new sub menu if (!$parent = $theUL){$this->fullNav[] .= '<ul class="topNav">'; } // retrieve all children of $parent $getNav = DbConnector::query("SELECT `ID`, `NAME`, `PARENT`, `EDIT`, `TIER_POS` FROM rcms_pages WHERE `PARENT` = '".$parent."' ORDER BY `TIER_POS` ASC"); // New link actions while ($gotNav = mysql_fetch_array($getNav)) { $UL = $parent; $item ++; // Does the page have children $getChild = DbConnector::query("SELECT * FROM rcms_pages WHERE `PARENT` = '".$gotNav['ID']."'"); // Construct the menu item $link .= '<li>'; if(DbConnector::fetchArray($getChild)){ $link .= '<a title="Expand/Collapse" href="javascript:toggleLayer(\''.$item.'\');"><img src="img/nav-expand-on.gif" width="14" height="14" alt="Expand/Collapse" class="navExpandImg" /></a>' ;}
[code]else{ $link .= '<img src="img/nav-expand-off.gif" width="14" height="14" class="navExpandImg" />' ;} $link .= '<div class="Fleft">'.$gotNav['NAME'].'</div><img src="img/nav-edit-off.gif" width="14" height="14" alt="Edit Page" class="navIcons" /><img src="img/nav-delete-off.gif" width="14" height="14" alt="Delete Page" class="navIcons" /><div class="navModule"></div><div class="clear"></div></li>'."\n\n"; // add this item to the navigation $this->fullNav[] .= $link; // empty current link incase of sub links $link = ""; // Display any children to this menu item $this->ShowPageTree($gotNav['ID'], $level+1, $item, $parent); } if (!$parent = $theUL){$this->fullNav[] .= '</ul>';} // echo complete navigation return implode($this->fullNav); } } The problem is that my new link data is not being added to the $fullNav array, the instruction to pass the link to the array is marked up above (HERE>>>>)
All the gets returned is
<ul class="topNav"></ul>
I know that the link is being constructed ok as I've tried just returning this on its own, and to double check even if I change the instruction mentioned to
// add this item to the navication $this->fullNav[] .= 'HELLO CAN YOU SEE ME'; I still only get
<ul class="topNav"></ul>
I'm quite new to OOP and functions in general so apologies for any shocking code here
$this->fullNav[] .= $link;
Looks like you're using string techniques while working with arrays.
* If you want to concatenate something to an existing string: use
$string .= $piece;
$array[] = $item;
if (!$parent = $theUL)
You probably mean
if (!$parent == $theUL)
I'm currently looking at
function ShowPageTree($parent, $level, $item, $theUL){ // Check if we're opening a new menu or sub menu
if ($theUL == 'new'){ $fullNav .= '<ul class="topNav">OPEN UL'."\n"; } if (!$parent == $theUL){ $fullNav .= '<li id="subnav'.$item.'" style="border:none;"><ul class="expandingNav">OPEN SUB UL'."\n"; } // retrieve all children of $parent
$getNav = DbConnector::query("SELECT `ID`, `NAME`, `PARENT`, `EDIT`, `TIER_POS` FROM rcms_pages WHERE `PARENT` = '".$parent."' ORDER BY `TIER_POS` ASC;"); // begin child actions
while ($gotNav = DbConnector::fetchArray($getNav)) { $UL = $parent; $item ++; $getChild = DbConnector::query("SELECT * FROM rcms_pages WHERE `PARENT` = '".$gotNav['ID']."';"); // Construct the menu item
$link = '<li>'; if(DbConnector::fetchArray($getChild)){ $link .= '<a title="Expand/Collapse" href="javascript:toggleLayer(\''.$item.'\');"><img src="img/nav-expand-on.gif" width="14" height="14" alt="Expand/Collapse" class="navExpandImg" /></a>' ;} else{ $link .= '<img src="img/nav-expand-off.gif" width="14" height="14" class="navExpandImg" />' ;} $link .= '<div class="Fleft">'.$gotNav['NAME'].'</div>'; $link .= '<a title="Edit Page" href="editpage.php?page='.$gotNav['ID'].'"><img src="img/nav-edit-on.gif" width="14" height="14" alt="Edit Page" class="navIcons" /></a>'; $link .= '<a title="Delete Page" href="'.$_SERVER['PHP_SELF'].'?delete='.$gotNav['ID'].'"><img src="img/nav-delete-on.gif" width="14" height="14" alt="Delete Page" class="navIcons" /></a>'; $link .= '<div class="navModule"></div>'; $link .= '<div class="clear"></div></li>'."\n"; // add this item to the navigation
$fullNav .= $link; // Check what's going on
$fullNav .= '[ID:'.$gotNav['ID'].'//tier:'.$level.'//item:'.$item.'//tiername:'.$UL.']'; // Display any children to this menu item
$this->ShowPageTree($gotNav['ID'],$level+1,$item,$UL); } // clost the current UL if all items are retrieved STILL NEEDS ATTENTION!
if ($parent == $theUL){$fullNav .= '</ul>CLOSE'."\n";} //if (!$parent == $theUL){$fullNav .= '</ul>CLOSE'."\n";} // return complete navigation
return $fullNav; } My output looks like this:
OPEN UL
(expand button off) Robo Page 3 (other buttons with correct IDs)
[ID:3//tier:0//item:1//tiername:nav]
(expand button off) Robo Page 2(other buttons with correct IDs)
[ID:2//tier:0//item:2//tiername:nav]
(expand button on) Robo Page 1(other buttons with correct IDs)
[ID:1//tier:0//item:3//tiername:nav]
----------------------------------------
which means that the recursive part of the script isn't working correctly as Robo Page 1 should have 2 children
I know they can be picked up ok because if I call the function like this:
$PageTree->ShowPageTree(1,0,0,'new')
they list correctly
I think i'm very nearly there - I've probably been looking at this for too long so I'm beginning to overlook silly mistakes.