Multi level menu with PHP/MySQL -


I am trying to create dynamic multi level menus to get data from a MySQL DB using PHP. I managed to arrange menu items in a PHP array with this format:

  ----------------------- Array ([1] = & gt; Array ([ID] => 1 [ubicacion] => top_A [net] => 1 [parent_id] => [tipo] => Link [Link] = & gt; http://www.google.com [titulo] => Google [alias] => google_es [children] => array ([3] => hey ( [ID] => [[ubicacion] = & gt; Top_A [net] => 2 [parent_id] => 1 [tipo] => link [link] => http: / /www.gmail.com [titulo] = & gt; Gmail [nickname] = array ([4] = & gt; array ([ID] => 4 [ubicacion] => top_A [net] = & Gt; 3 [original [identity]] => 3 [tipo] = & gt; S [link] => www.inbox.gmail.com [titulo] = & gt; Inbox [nickname] => Inbox_Gmail))))) [2] = & gt; Array ([ID] = & Gt; 2 [ubicacion] = & gt; Top_A [Net] => 1 [parent_id] => [Tipo] = & gt; Link [Link] => http://www.yahoo.com [Titulo] = & gt; Yahoo [nickname] => Yahoo)) -----------------------   < P> The problem is that I can not figure out how this array is as a way of HTML markup, which will work with the n level, I can do this with certain levels:  
  foreach ($ menu_array $ as menu ) {Echo "
  • gt; & Lt; A href = '{$ menu [' link ']}' & gt; {$ Menu ['title']} & lt; / A & gt; "; If (array_key_exists ('kids', $ menu)) {resonant" & lt; Ul & gt; "; foreign currency ($ menu ['children'] as $ child_menu {resonance
  • gt; ul>"; ($ Child_menu ['titulo']} & gt; {$ child2_menu ['titulo']} & lt; / $ {$ child2_menu ['title']} & gt; One & gt; "echo" & lt; / Ul & gt; "}}} echo" "echo" ";}

    but this is only 3 Works for the levels, and I know that there should be a way to solve this problem, I know that I am facing a problem with the HTML production for the first time multidimensional array.

    You only use some recycling to reach higher levels function echo_menu ($ menu_array) {// go through every top level menu item foreach ($ menu_array $ menu) {echo "lt; li & gt; & lt ; A href = '{$ menu [' link ']}' & gt; {$ menu ['title']} & lt; / a & gt; "; // See if there are children in this menu (array_key_exists ( Echo & lt; ul & gt; '; // hair menu resonance echo ($ menu [' children ']); echo & lt; / ul & gt;';} echo & quot; Lt; / li & gt; ';}} echo' & lt; Ul & gt; '; Echo_menu ($ menu_array); Echo & lt; / Ul & gt; ';

    It will work for any child level that you want.

  • Comments