Jump to content

Dynamic sub menus help


brob

Recommended Posts

Hi can anyone help.

here is the code for the menu
[code]
$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>';

[/code]
and here is the mysql table

[code]
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
[/code]

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.