TechMistress Posted February 4, 2009 Share Posted February 4, 2009 Hi All, I'm hoping someone can help me with this. I'm trying to create a dynamic dropdown menu from items in a mysql table. I found this great code - and it's close, but it generates the menu (through several files) using TWO tables, which they call menu and submenu. My categories table consists of the following: cat_id, parent_id, cat_name. How can I modify the below code to use just my one table, rather than their two. If it cannot be done, does anyone know of a nice dropdown menu that will show my parent cats and the subcats assigned to them beneath? Thank you, here is the query snippet: /* FUNCTIONS RETURNS PHP TO BUILD OBJECTS; */ function menu(){ global $result_array; db_connect(); $query = "SELECT * FROM menu"; $result = mysql_query($query); $result_array = array(); db_close(); while($row = mysql_fetch_array($result)){ $result_array[] = $row; } return $result_array; } function sub_menu($id){ global $result_array; db_connect(); $query = "SELECT * FROM sub_menu WHERE parent_id=$id ORDER BY title_sub"; $result = mysql_query($query); $result_array = array(); db_close(); while($row = mysql_fetch_array($result)){ $result_array[] = $row; } return $result_array; } $top_menu = menu(); for($i=0;$i<count($top_menu);$i++){ extract($top_menu[$i]); $menu[$i]=new menu("$parent_id","$title","$width","$url","$target"); $sub_menu=sub_menu($parent_id); for($j=0;$j<count($sub_menu);$j++){ extract($sub_menu[$j]); $submenu[$i][$j]=new submenu("$sub_id","$title_sub","$url_sub","$target_sub"); } } /* INSTANTIATING THE MENU AND SUBMENU CLASSES */ class menu { function menu($parent_id,$title, $width, $url, $target) { $this->PARENT_ID = $parent_id; $this->TITLE = $title; $this->WIDTH = $width; $this->URL = $url; $this->TARGET = $target; } } class submenu { function submenu($sub_id,$title, $url, $target_sub) { $this->SUB_ID = $sub_id; $this->TITLE = $title; $this->URL = $url; $this->TARGET = $target_sub; } } Link to comment https://forums.phpfreaks.com/topic/143813-solved-i-just-cant-figure-this-dropmenu-out/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.