Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerate megamenu from adjacency list
    primarykey
    data
    text
    <p>I have an array below: </p> <pre><code>Array ( [0] =&gt; Array ( [id] =&gt; 1 [name] =&gt; Electronics [parent] =&gt; 0 [description] =&gt; Large amount of electronics in our store [columns] =&gt; 6 [products] =&gt; 5 [subcat] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 7 [name] =&gt; Moble phones [parent] =&gt; 1 [description] =&gt; [columns] =&gt; 0 [products] =&gt; 5 [subcat] =&gt; Array ( ) ) [1] =&gt; Array ( [id] =&gt; 16 [name] =&gt; Computers [parent] =&gt; 1 [description] =&gt; [columns] =&gt; 0 [products] =&gt; 0 [subcat] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 37 [name] =&gt; Desktops [parent] =&gt; 16 [description] =&gt; [columns] =&gt; 0 [products] =&gt; 0 [subcat] =&gt; Array ( ) ) [1] =&gt; Array ( [id] =&gt; 17 [name] =&gt; Car Electronics [parent] =&gt; 16 [description] =&gt; [columns] =&gt; 0 [products] =&gt; 0 [subcat] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 43 [name] =&gt; GPS &amp; Navigation [parent] =&gt; 17 [description] =&gt; [columns] =&gt; 0 [products] =&gt; 0 [subcat] =&gt; Array ( ) ) ) ) ) ) [2] =&gt; Array ( [id] =&gt; 18 [name] =&gt; TV &amp; Video [parent] =&gt; 1 [description] =&gt; [columns] =&gt; 0 [products] =&gt; 2 [subcat] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 48 [name] =&gt; LED TVs [parent] =&gt; 18 [description] =&gt; [columns] =&gt; 0 [products] =&gt; 2 [subcat] =&gt; Array ( ) ) [1] =&gt; Array ( [id] =&gt; 49 [name] =&gt; Plasma TVs [parent] =&gt; 18 [description] =&gt; [columns] =&gt; 0 [products] =&gt; 0 [subcat] =&gt; Array ( ) ) ) ) ) ) [1] =&gt; Array ( [id] =&gt; 14 [name] =&gt; Video Games [parent] =&gt; 0 [description] =&gt; [columns] =&gt; 0 [products] =&gt; 0 [subcat] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 30 [name] =&gt; Nintendo Wii [parent] =&gt; 14 [description] =&gt; [columns] =&gt; 0 [products] =&gt; 0 [subcat] =&gt; Array ( ) ) ) ) ) </code></pre> <p>I have a php recursive function to convert this array into html menu:</p> <pre><code>private function buildNavHTML($nav, $tabs = "") { $html = !strlen($tabs) ? $tabs.'&lt;ul class="navs"&gt;' : $tabs.'&lt;ul&gt;'; foreach($nav as $page) { $html .= $tabs." ".'&lt;li&gt;'; (isset($page['subcategories'][0])) ? $html .= '&lt;a class="subcat" href="cat?cid='.$page['id'].'"&gt;'.$page['name'].'&lt;/a&gt;' : $html .= '&lt;a href="cat?cid='.$page['id'].'"&gt;'.$page['name'].'&lt;/a&gt;'; if(isset($page['subcat'][0])) { $html .= self::buildNavHTML($page['subcat'], $tabs." "); } $html .= '&lt;/li&gt;'; } $html .= $tabs.'&lt;/ul&gt;'; return $html; } </code></pre> <p>And this function will output HTML tree:</p> <pre><code> &lt;ul class="navs"&gt; &lt;li class=""&gt; &lt;a class="shop_subcat" href="cat?cid=1"&gt;Electronics&lt;/a&gt; &lt;ul&gt; &lt;li&gt; &lt;a href="cat?cid=7"&gt;Moble phones&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a class="shop_subcat" href="cat?cid=16"&gt;Computers&lt;/a&gt; &lt;ul&gt; &lt;li&gt; &lt;a href="cat?cid=37"&gt;Desktops&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a class="shop_subcat" href="cat?cid=17"&gt;Car Electronics&lt;/a&gt; &lt;ul&gt; &lt;li&gt; &lt;a href="cat?cid=43"&gt;GPS &amp;amp; Navigation&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt; &lt;a class="shop_subcat" href="cat?cid=18"&gt;TV &amp;amp; Video&lt;/a&gt; &lt;ul&gt; &lt;li&gt; &lt;a href="cat?cid=48"&gt;LED TVs&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="cat?cid=49"&gt;Plasma TVs&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li class=""&gt; &lt;a class="shop_subcat" href="cat?cid=14"&gt;Video Games&lt;/a&gt; &lt;ul&gt; &lt;li&gt; &lt;a href="cat?cid=30"&gt;Nintendo Wii&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>But I need to get something like that: _http://vasterad.com/plugins/responsive_css3_mega_menu/#</p> <p>Separated by columns as I have a columns field in my database. How can I fix my recursion function? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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