function generate_menu($parentID,$menu_array=Array(), $level = 0, $first=0)
{
  $has_childs = false;
  if (empty($menu_array)) {
  $rs = mysql_query("SELECT catID, parentID, catName FROM ha_shop_cats");
 while ( $row = mysql_fetch_assoc($rs) )
 {
 $menu_array[$row['catID']] = array('catName' => $row['catName'],'parentID' =>         $row['parentID'],'catID'=>$row['catID']);
 }
 }

foreach ($menu_array as $key => $value)
{

if ($value['parentID'] == $parentID)
{
//if this is the first child print '<ul>'
if ($has_childs === false) {
//don't print '<ul>' multiple times
$has_childs = true;
if ($first == 0){
echo "<ul id=\"nav\">\n";
$first = 1;
} else {
echo "\n<ul>\n";
}
}
$pad = str_repeat('– ', $level);
echo "<li><a href=\"" . $value['catID'].'">' . $value['catName'] . "</a>";
$this->generate_menu($key, $menu_array, $level + 1, $first);
//call function again to generate nested list for subcategories belonging to this category
echo "</li>\n";
}
}
if ($has_childs === true) echo "</ul>\n";
}
--
-- Table structure for table `ha_shop_cats`
--CREATE TABLE IF NOT EXISTS `ha_shop_cats` (
`catID` int(11) unsigned NOT NULL AUTO_INCREMENT,
`parentID` int(11) unsigned NOT NULL DEFAULT '0',
`catName` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`catSafe` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`description` text COLLATE utf8_unicode_ci,
`dateCreated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`dateModified` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`catOrder` int(11) DEFAULT NULL,
`deleted` tinyint(1) unsigned NOT NULL DEFAULT '0',
`siteID` int(11) DEFAULT NULL,
PRIMARY KEY (`catID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=42 ;

--
-- Dumping data for table `ha_shop_cats`
--

INSERT INTO `ha_shop_cats` (`catID`, `parentID`, `catName`, `catSafe`, `description`, `dateCreated`, `dateModified`, `catOrder`, `deleted`, `siteID`) VALUES
(13, 0, 'ART', 'art', '', '0000-00-00 00:00:00', '2012-10-08 09:58:00', 1, 0, 1),
(14, 0, 'MUSIC', 'music', 'yttyryr', '0000-00-00 00:00:00', '2012-10-30 04:56:28', 2, 0, 1),
(15, 13, 'Graffiti', 'graffiti', '', '0000-00-00 00:00:00', '2012-10-08 09:59:03', 2, 0, 1),
(16, 13, 'Gallery', 'gallery', '', '0000-00-00 00:00:00', '2012-10-08 09:59:24', 1, 0, 1),
(17, 13, 'Photography', 'photography', '', '0000-00-00 00:00:00', '2012-10-08 10:00:27', 3, 0, 1),
(18, 14, 'Hip-Hop', 'hip-hop', '', '0000-00-00 00:00:00', '2012-10-08 10:02:06', 1, 0, 1),
(20, 14, 'House', 'house', '', '0000-00-00 00:00:00', '2012-10-08 10:02:54', 2, 0, 1),
(21, 14, 'Dubstep', 'dubstep', '', '0000-00-00 00:00:00', '2012-10-08 10:03:08', 4, 0, 1),
(22, 14, 'Electronic', 'electronic', '', '0000-00-00 00:00:00', '2012-10-08 10:03:25', 3, 0, 1),
(24, 14, 'Rock', 'rock', '', '0000-00-00 00:00:00', '2012-10-08 10:04:46', 6, 0, 1),
(25, 14, 'Hardcore', 'hardcore', '', '0000-00-00 00:00:00', '2012-10-08 10:05:05', 5, 0, 1),
(26, 14, 'Punk Rock', 'punk-rock', '', '0000-00-00 00:00:00', '2012-10-08 10:05:20', 7, 0, 1),
(27, 14, 'Jazz', 'jazz', '', '0000-00-00 00:00:00', '2012-10-08 10:05:39', 8, 0, 1),
(41, 40, '3n level', '3n-level', '', '0000-00-00 00:00:00', '2012-11-03 06:47:58', NULL, 0, 1),
(40, 34, 'subcate 2 level', 'subcate 2 level', 'gfhgfh', '0000-00-00 00:00:00', '2012-11-03 05:29:49', NULL, 0, 1),
(31, 0, 'FASHION', 'fashion', '', '0000-00-00 00:00:00', '2012-10-30 05:30:39', 3, 0, 1),
(34, 31, 'Streetwear', 'streetwear', '', '0000-00-00 00:00:00', '2012-10-30 05:31:12', NULL, 0, 1);
Advertisements