Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy my menu is not hierarchical?
    text
    copied!<p>I want to create a hierarchical menu. The function:</p> <pre><code>/* * 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 "&lt;ul&gt;"; while ($node = mysql_fetch_array($result)) { echo "&lt;li&gt;".$node['name']; $hasChild = mysql_fetch_array(mysql_query("SELECT * FROM `menus` WHERE `submenu` = ".$node['id'])) != null; IF ($hasChild) { showMenu($node['id']); } echo "&lt;/li&gt;"; } echo "&lt;/ul&gt;"; } </code></pre> <p>I've found on a stackoverflow in a similar question.</p> <p>I have a table <code>menus</code>:</p> <pre><code>+----+----------------+---------+ | 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 | +----+----------------+---------+ </code></pre> <p>I used this function in script</p> <pre><code>showMenu(4); </code></pre> <p>and here is the result:</p> <pre><code>&lt;ul&gt;&lt;li&gt;item 1&lt;/li&gt;&lt;li&gt;item 2&lt;/li&gt;&lt;/ul&gt; </code></pre> <p>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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload