Re: Dynamic menu from DB

From: Date: Thu, 09 Jan 2003 19:06:40 +0000
Subject: Re: Dynamic menu from DB
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-130991@lists.php.net to get a copy of this message
I don't know about the flash part, but submenus are simple. Your menu items table needs a "parent" column, where the id of the parent menu item, but for top level menus (Flash static menu) it will be 0. Then first select all menu items with parent=0 and as you loop throught the result result, recursively get all child elements. This function will get you started: get_childs($menu_id) { $resp=array(); $res=mysql_query("SELECT * FROM menu_items WHERE menu_parent_id='$menu_id'"); if(mysql_num_rows($res)) {
       for($i=0;$tmp=mysql_fetch_array($res); $i++) {
           $resp[$i]['menu']=$tmp; // ['menu'] will contain info about particular menu item
           $resp[$i]['childs']=get_childs($tmp['menu_id']); // ['menu'] will contain all childs of this menu items, each child will again contain ['menu'] and ['childs'] etc.
       }
} return $resp; } $menu_tree = get_childs(0); echo '<pre>'; print_r($menu_tree); echo '</pre>'; Cesar Aracena wrote:
Hi all, I'm making a new site for a client and he needs to put several different menus under a static FLASH menu. The bad part is that every item in the flash menu leads to different categories and these need different number of sub menus. I use MySQL & PHP 4. The categories and sub categories are something like this: * Products <-- Flash static menu - Item 1 <-- MySQL fetched menu - Item 2 <-- MySQL fetched menu - Item 3 <-- MySQL fetched menu - Item 3-1 <-- MySQL fetched menu - Item 3-2 <-- MySQL fetched menu * Services <-- Flash static menu - Item 1 <-- MySQL fetched menu - Item 1-1 <-- MySQL fetched menu - Item 1-2 <-- MySQL fetched menu - Item 2 <-- MySQL fetched menu - Item 3 <-- MySQL fetched menu What would be the best solution for this? Another problem to solve is the creation of new children into the menu... sub categories AND items dynamically. Thanks in advance, Cesar L. Aracena icaam@icaam.com.ar caracena@infovia.com.ar (0299) 156-356688 Neuquén (8300) Capital Argentina


« previous php.general (#130991) next »