|
Posted by Gregory Machin on 08/16/05 16:09
Here it is..
i found the problem.. 1) all the menu objects->arrChildren have an array ,
if there are on submenus.. then the array is empty .. the function was
trying to recurse through empty arrays. 2) the recursive call needed to
pass the arrChildren to recurse correctly
"display_menu($value->arrChildren);"
now just to get the html output and css to live together :-)...
Thanks All form the support, all bets greg..
<?php
$link = mysql_connect("127.0.0.1", "root", "");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// make the current db
$db_selected = mysql_select_db('NEW_CMS', $link);
if (!$db_selected) {
die (" can't connect to database : " . mysql_error());
}
class MenuItem
{
var $intID = 0;
var $names = '';
var $arrChildren = array( );
//
// Constructor
function MenuItem ( $intID, $text )
{
$this->intID = $intID;
$this->names = $text;
$this->addChildren( );
}
function addChildren ( )
{
$strSQL = "select id, name from newCMS_section where Parent = "..
$this->intID ."";
$rseResult = mysql_query($strSQL);
while ( $arrRecord = mysql_fetch_array( $rseResult, MYSQL_BOTH ) )
{
$this->arrChildren[] = new MenuItem( trim( $arrRecord[0] ),
trim($arrRecord[1]) );
}
}
}
$Menu =& new MenuItem(0,'');
$txt = $Menu->arrChildren;
function display_menu($array) {
$link ='';
$namez ='';
foreach ($array as $key => $value) {
if(empty($value->arrChildren)){ //arrChildren =>Array
// problem was with the above if statment.
$namez = $value->names;
$link = $value->names;
echo "<li><a href='{$link}'>{$namez}</a></li>\n";
} else {
$namez = $value->names;
echo "<ul><li><a>{$namez}</a><ul>";
display_menu($value->arrChildren);
echo '</ul></li></ul>';
} // end of else
} // end of foreach loop
} // end of function
//echo "<ul>";
echo "<ul id='nav' >";
display_menu($txt);
?>
--
Many Thanks
Gregory Machin (flamer)
072 524 8096
www.linuxpro.co.za
greg@linuxpro.co.za
Agent for iberry.info hosting solutions
--
Navigation:
[Reply to this message]
|