473,322 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

forgetable arrays

Hi,
I'm having trouble with my code:

<?php
/**
* Contains classes to easyly create an XHTML navigation frame.
*
* plancode.com
* Bauplanmanagment im Netz
*
* <p>Contains classes to create an XHTML navigation frame. The main
class is menu. See there for details</p>
*
* @version 0.1
* @see menu
* @author Bj&ouml;rn Keil <ke**@plancode.com >
* @since 19.11.2003
* @package Administration
* @copyright plancode.com 19.11.2003
*/

/**
* A single menu entry for the navigation bar
*
* @since 19.11.2003
* @author Bjoern Keil <ke**@plancode.com>
*/
class menunode {
/**
* Contains the title of a menu entry
* @access public
* @var string
*/
var $title;

/**
* Contains the base directory of the referenced item
* @access public
* @var string
*/
var $directory;

/**
* Contains the filename of the menu entry
* @access public
* @var string
*/
var $file;

/**
* Conains the parentnode or null for root nodes
* @access private
* @var menunode
*/
var $parent;

/**
* Contains an array of child nodes
* @access public
* @var array of menunode
*/
var $children;

/**
* Constructor, initializes base fuctions
* @param string The title of the function
* @param string The base directory in wich the file belonging to the
entry may be found
* @param string The name of the file belonging to the directory
entry <i> The directory has to be empty or end with "/"</i>
*/
function setNode ($title, $directory, $file) {
$this->title = $title;
$this->directory = $directory;
$this->file = $file;
$this->children = array();
}

/**
* Set the parent for the current node
* @param menunode The node to be set as parent
*/
function setParent ($parent) {
$this->parent = $parent;
}

/**
* Creates a new child node and sets it up
* @param string The title of the child menuentry
* @param string The directory of the child node relative to the
current node. <i>Has to be empty or end with "/"</i>
* @param string The name of the file linked from the menu
* @return menunode the newly created menuentry
*/
function addChild ($title, $subdir, $file) {
$newchild = new menunode;
$newchild->setNode($title, $this->directory.$subdir, $file);
$newchild->setParent($this);
$this->children[] = $newchild;
return $newchild;
}

/**
* Draw the menustarting from this node into a string
* @return string containing XHTML code for menu
*/
function draw() {
$menustring = "<li><a href=\"$this->directory$this->file\"
target=\"content\">$this->title</a></li>\n";
echo current($this->children);
if (count($this->children) > 0) {
$menustring .= "<ul>\n";
foreach ($this->children as $currentnode) {
$menustring .= $currentnode->draw();
}
$menustring .= "</ul>\n";
}
return $menustring;
}

}
/**
* Create a simple menu
*
* Usage:
* <code>
* $mymenu = new menu;
* $mymenu -> setNode("Menu title", "Menulink directory", Menulink
file");
* $mymenu->addChild("Entry title", "Entry directory", "Entry file");
* $first_level_entry = $mymenu->addChild("Entry title", "Entry
subdirectory", "Entry file");
* $second_level_entry =
* $first_level_entry->addChild("Entry title", "Entry subdirectory",
"Entry file");
* $second_level_entry =
* $first_level_entry->addChild("Entry title", "", "Entry file");
*
* echo $mymenu->create();
* </code>
* <i>Warning:
* <ol>
* <li>The directory and subdirectories must end with a "/" or
* be left empty as in the example above if the the files of next
* menu level are in the same directory</li>
* <li>All directory entries are relative to the level above. I.E.
only the menu root
* item may contain an absolute adress.</li>
* <li>Off course, directories & subdirectories may not start with a
"/"</li>
* <li>Menu & entry titles have to be XHTML code. Special characters
have to be represented
* with the proper HTML sequences like: &nbsp;</li>
* </ol>
* </i>
*/
class menu extends menunode {

/**
* Create the XHTML code for the whole menu
* @return string containing the XHTML code
*/
function create() {
$menustring = "<h2><a href=\"$this->directory$this->file\"
target=\"content\">$this->title</a></h2>\n";
$currentnode = current($this->children);
if (count($this->children) > 0) {
$menustring .= "<ul>\n";
foreach ($this->children as $currentnode) {
$menustring .= $currentnode->draw();
}
$menustring .= "</ul>\n";
}
return $menustring;
}
}
?>

The Problem is, it generates the first level of the menu without any
problems. But once it tries to access the 2nd level nodes from the
first level nodes it seems to have forgotten what there are any child
nodes. I used this code for testing:
<?PHP
require_once "menu.php";

$newmenu = new menunode;
$newmenu->setnode("Navigation","","");
$level1 = $newmenu->addChild("Punkt 1","","");
$level1->addChild("Punkt a","","");
$newmenu->addChild("Punkt 2","","");
$newmenu->addChild("Punkt 3","","");
$newmenu->addChild("Punkt 4","","");
$newmenu->addChild("Punkt 5","","");
echo $newmenu->create();
echo $level1->children[0]->title;
?>

Sorry for the long post and thanks ahead.
Björn Keil
Jul 17 '05 #1
1 2037
I'm too lazy to read all your code but I have previously helped someone
else to build a heirachial menu from a database table.

see my post on thread

"Simple menu, MySQL query question"

Who knows, maybe you might even use it :)

I don't know if the original poster of that thread used it, he didn't
bother to reply.

If you can't find the thread, I'll dig up the code and send it to you.
At the moment, it makes XML but you could easily make it produce HTML.

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jason | last post by:
I have a number of arrays that are populated with database values. I need to determine which array has the highest ubound out of all the arrays. The array size will always change based on the...
19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
3
by: Michel Rouzic | last post by:
It's the first time I try using structs, and I'm getting confused with it and can't make it work properly I firstly define the structure by this : typedef struct { char *l1; int *l2; int Nval; }...
1
by: Rob Griffiths | last post by:
Can anyone explain to me the difference between an element type and a component type? In the java literature, arrays are said to have component types, whereas collections from the Collections...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
16
by: mike3 | last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms- windows.programmer.win32 since there's Windows material in here as well as questions related to standard C++. Not sure how that'd go over...
29
weaknessforcats
by: weaknessforcats | last post by:
Arrays Revealed Introduction Arrays are the built-in containers of C and C++. This article assumes the reader has some experiece with arrays and array syntax but is not clear on a )exactly how...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.