Jump to content


Photo

Dynamic sub menus help


  • Please log in to reply
No replies to this topic

#1 brob

brob
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 06 October 2006 - 01:02 PM

Hi can anyone help.

here is the code for the menu
$host = "localhost";
$dbuser = "un";
$dbpassword = "pass";
$database = "dev-cwc";

$link = mysql_connect($host,$dbuser,$dbpassword);

$db_selected = mysql_select_db($database);
if (!$db_selected) {
   die ('Can\'t select database : ' . mysql_error());
}
$getitemid = explode("Itemid=",$url);
$Itemid = $getitemid[1];

echo '<table cellpadding="0" cellspacing="0" class="moduletabletestmenu"><tr><td><table width="100%" border="0" cellpadding="0" cellspacing="0">';

$mainmenu = mysql_query("select * from mos_menu where menutype = 'mainmenu' and published = '1' and parent = '0' order by ordering asc");
while($gotmainmenu = mysql_fetch_array($mainmenu))
{
	echo "<tr align='left'><td><a href='/$gotmainmenu[3]&Itemid=$gotmainmenu[0]' class='mainlevelmark' "; if ($Itemid == $gotmainmenu[0]){echo "id='active_menumark'";} echo ">$gotmainmenu[2]</a>";
	
	$getlevel = mysql_query("select * from mos_menu where id = '$Itemid'");
	$gotlevel = mysql_fetch_row($getlevel);
	#echo "$gotlevel[6]<br>";
	
	$submenu = mysql_query("select * from mos_menu where menutype = 'mainmenu' and published = '1' and parent = '$gotmainmenu[0]' order by ordering asc");
	while($gotsubmenu = mysql_fetch_array($submenu))
	{	

		echo "<div style='padding-left: 4px'><a href='/$gotsubmenu[3]&Itemid=$gotsubmenu[0]' class='sublevelmark' "; if ($Itemid == $gotsubmenu[0]){echo "id='active_menumark'";} echo ">$gotsubmenu[2]</a></div>";

	}
	echo"</td></tr>";
}
echo '</table></td></tr></table>';

and here is the mysql table

Field	Type	Null	Default
id	int(11)	No	
menutype	varchar(25)	Yes	NULL
name	varchar(100)	Yes	NULL
link	text	Yes	NULL
type	varchar(50)	No	
published	tinyint(1)	No	0
parent	int(11) 	No	0
componentid	int(11) 	No	0
sublevel	int(11)	Yes	0
ordering	int(11)	Yes	0
checked_out	int(11) 	No	0
checked_out_time	datetime	No	0000-00-00 00:00:00
pollid	int(11)	No	0
browserNav	tinyint(4)	Yes	0
access	tinyint(3) 	No	0
utaccess	tinyint(3) 	No	0
params	text	No	

I have got the main level to work correctly and it will show the sub menu's, but when you click on the sub menu it doesn't keep the top level open to show the sub level anymore.

This isn't a css issue its something to do with the second while loop.

Please I have a mental block and can't figure it out.

Please help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users