Announcement

Collapse
No announcement yet.

Menu Function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Menu Function

    I am attempting to build a tool for a client that has a navigation menu on the left hand side. It is setup so they can add as many categories and subcategories as they want and they could have an infinite level of sub categories inside of each other.

    To make more sense of this the menu could look something like this...

    1
    -- 1.1
    -- 1.2
    ------ 1.1.1

    2
    -- 2.1

    3
    -- 3.1
    -- 3.2
    -- 3.3
    ----- 3.1.1
    ----- 3.1.2
    -----------3.2.1


    and it could go on forever like that.

    All of this data is stored in a database and each record has a field to note the parent category.

    Does anyone have any suggestions how to write some code that will be able to pull all of this data out and print out the menu with out the menu.

    The problem i am running into now is if there is a possibility of having an infinite number of levels how to set the code to go as deep as the last level with out knowing how deep it goes.

    I have a half working version now but its all based off of knowing how many times to run a certain loop and knowing the number of levels there are to the menu.

    This may not be the clearest explanation, so if you need anymmore info let me know.

    Thanks!

  • #2
    Use recursion; that is a function that calls itself recursively which will lead to theoretically endless levels of categories.
    Read: http://au3.php.net/manual/en/language.functions.php
    Search for the "Recursion" examples.

    Comment

    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
    Working...
    X