www.webdeveloper.com
Results 1 to 3 of 3

Thread: Crawling through a menu tree

  1. #1
    Join Date
    Oct 2009
    Posts
    65

    Question Crawling through a menu tree

    I'm working on a light-weight CMS and I have a table of menu items that I want to administer. The relevant fields for this question are

    menu_item_id (PRIMARY KEY)
    menu_item_parent
    menu_item_status(PUBLISHED, UNPUBLISHED, TRASH)

    If there are sub-menus, their menu_item_parent is set to the menu_item_id of the parent menu item. If I change the menu_item_status of a parent, I want the effect to cascade down through all the child menus, however many levels deep.

    I tried doing this with a recursive function in PHP but the process would hang on me. I'd rather do it on the level of MYSQL if that's possible. Is there a MYSQL solution for this?

  2. #2
    Join Date
    Oct 2009
    Posts
    658

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    You might also consider using a nested set hierarchical structure for the data instead of the parent/child (adjacency list) structure.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles