Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9189273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:12:10+00:00 2026-06-17T20:12:10+00:00

I want to create a hierarchical menu. The function: /* * Table has 3

  • 0

I want to create a hierarchical menu. The function:

/*
* Table has 3 fields: `ID`, `PARENTID` and `NAME`
* `ID` is unique, `PARENTID` showing his parent node id.
* This function will go through it and build unordered list and call itself when needed to build subitems.
* $level argument used to define wich node's subitems to build. Default is 0 which is top level.
*/    
function showMenu($level = 0) {

$result = mysql_query("SELECT * FROM `menus` WHERE `submenu` = ".$level); 
echo "<ul>";
    while ($node = mysql_fetch_array($result)) { 
        echo "<li>".$node['name'];
        $hasChild = mysql_fetch_array(mysql_query("SELECT * FROM `menus` WHERE `submenu` = ".$node['id'])) != null;
        IF ($hasChild) {
            showMenu($node['id']);
        }
        echo "</li>";
    }
echo "</ul>";
}

I’ve found on a stackoverflow in a similar question.

I have a table menus:

+----+----------------+---------+
| id | name           | submenu |
+----+----------------+---------+
|  1 | FIRST HEADER   |    NULL | 
|  2 | SECOND HEADER  |    NULL | 
|  3 | THIRD HEADER   |    NULL | 
|  4 | (fh) submenu 1 |       1 | 
|  5 | (fh) submenu 2 |       1 | 
|  6 | (fh) submenu 3 |       1 | 
|  7 | (sh) submenu 1 |       2 | 
|  8 | (sh) submenu 2 |       2 | 
|  9 | (th) submenu 1 |       3 | 
| 10 | item 1         |       4 | 
| 11 | item 2         |       4 | 
+----+----------------+---------+

I used this function in script

showMenu(4);

and here is the result:

<ul><li>item 1</li><li>item 2</li></ul> 

as u can see, there is no word about even a piece of hierarchy, just a couple of items in source. What possibly wrong in my code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:12:11+00:00Added an answer on June 17, 2026 at 8:12 pm

    You are specifically requesting just the submenu number 4.

    If you just call showMenu() with no arguments, it will show the entire menu tree.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create my own hierarchical navigation menu control without using standart ASP.NET
I want to create a new field (or two) in my table that is
I have a hierarchical structure stored in a table. Each element has a pointer
I want to create a hierarchical view of strings based on first two characters.
I am trying to create hierarchical result with callbacks. This is my function structure:
I have a Hierarchical Table for Categories in this form NodeID ParentID NodeName Following
I want to create a hierarchical enum that represents a type that I can
I want to create a tar archive with a hierarchical directory structure from Python,
I want create new table out of magento, in interface, without inheriting setup class.
I am trying to get data from db table called Departments Id Name ParentId

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.