Deleting all items from menu

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
qperkins
Beginner
Beginner
Posts: 3
Joined: Wed Jan 19, 2005 5:56 am

Deleting all items from menu

Post by qperkins »

I need to dynamically add and delete from the menus. The way I would like to do this, is to call a script that empties a menu and then re-builds it based on user supplied info.

I can add and edit at will with the mm_changeItemProperty that Andy provided. It also allows for a remove a selected entry, but I need to erase an entire menu to rebuild. I would like either a script that would erase all of the entries in a selected menu or if someone could just help me identify the array I would need to zero, I could do it myself.

Can anyone please help me?
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

qperkins wrote:if someone could just help me identify the array I would need to zero, I could do it myself.
I don't know if this will give any kind of information that will help, but it has things about how to get a menu, positioning the menu, and talks later about how you find an item. It talks about how menu items are numbered 0 to xxxx and they are listed as el# something like that. It may have nothing related to what you are asking, since I don't really know anything about the internals of the menu. But it does talk about how items are identified. Sorry, I can't be of more help but it is really beyond my level of knowledge. http://milonic.com/forum/viewtopic.php?t=3632

Ruth
willemk
Beginner
Beginner
Posts: 5
Joined: Wed Feb 09, 2005 10:46 am
Location: Amsterdam

I have what you need....I think:)

Post by willemk »

Hi,

Check out http://www.slotracinglemans.com. he meu items under the submenu members are dynamically generated based on the user logged in.
If you are familiar with database driven websites it shouldn´t be that big of problem for you.

I use MYSQL and PHP. You can create a simple table like this for instance:

Code: Select all

CREATE TABLE menu (
  mid smallint(6) NOT NULL auto_increment,
  text varchar(40) NOT NULL default '',
  url varchar(40) NOT NULL default '',
  status char(3) NOT NULL default '',
  PRIMARY KEY  (mid),
  KEY text (text,url)
) TYPE=MyISAM;
In your code you can then do the following:

Code: Select all

$query = mysql_query("select * from menu where status = 'on'");
while($result = mysql_fetch_array($query)) {
        $menuitems .= "aI(\"text=$result[text];url=$result[url];\");\n";
}
The query only selects those rows you have given the value "on".
The while loop loops through the records and generates the meu items.
$menuitems can now be added to your existing menu whereever you want it to be.
Note: See the backslash and the n ( \n ) after each menu item being fetched. This makes it easier to view the source when you are testing.

A simple administrator page which lets you insert delete and change the menu items in the table and you are there.

Hopes this helps
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

Thanks for the information on the mysql/php based menu and deleting and rebuilding, wellemk. That's a great resource for any who use that kind of setup. We get queries on mysql/php, we appreciate the input!

Ruth
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Just reviewing some posts after being out of town last week...

Anyone interested in dynamically adding, modifying, or deleting menu items after the menus have been rendered on a page should review this topic, which discusses a recently added api for editing menus.

Cheers,

Kevin
Post Reply