<?php
$link = mysql_connect('localhost', 'root', 'root');
if (!$link) {
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db('libtest', $link);
if (!$db_selected) {
die ('Can\'t use libtest : ' . mysql_error());
}
function menutree($id,$level='0')
{
$level++;
$sql1 = " SELECT count(*) as COUNT1 FROM `menu` WHERE `menu_parent_id` =".$id;
$rs1 = mysql_query($sql1);
$count = mysql_fetch_array($rs1);
if($count["COUNT1"] > 0)
{
$sql2 = "SELECT * FROM `menu` WHERE `menu_parent_id` =".$id." order by menu_name";
$rs2 = mysql_query($sql2);
while( $row2 = mysql_fetch_assoc($rs2) )
{
?>
<option value="<?php echo $row2["menu_id"];?>" <?php if($row2["menu_id"] == $_REQUEST["menu_parent"] ){?> selected <?php } ?>>
<?php
for ($i=0;$i<$level;$i++) {
echo " ";
}
echo $row2["menu_name"];
?>
</option>
<?php
menutree($row2["menu_id"],$level);
}
}
}
?>
<select name="menu_parent" id="menu_parent" class="input">
<option value="0" <?php if( $_REQUEST["menu_parent"] == 0){ ?> selected <?php } ?>>Root</option>
<?php
$sql = " SELECT * FROM `menu` WHERE `menu_parent_id`=0 order by menu_name";
$rs = mysql_query($sql);
while( $row = mysql_fetch_assoc($rs) )
{
?>
<option value="<?php echo $row["menu_id"];?>" <?php if($row["menu_id"] == $_REQUEST["menu_parent"] ){?> selected <?php } ?>>
<?php echo $row["menu_name"];?>
</option>
<?php
menutree($row["menu_id"],'0');
}
?>
</select>
Database Details:
--
-- Table structure for table `menu`
--
CREATE TABLE `menu` (
`menu_id` int(10) NOT NULL auto_increment,
`mc_id` int(11) NOT NULL default '0',
`menu_name` varchar(150) collate utf8_unicode_ci NOT NULL default '',
`menu_parent_id` int(10) NOT NULL default '0',
`menu_order` int(10) NOT NULL default '0',
`menu_link` varchar(255) collate utf8_unicode_ci NOT NULL default '0',
`menu_pagemode` int(10) NOT NULL default '0',
`menu_created_date` datetime NOT NULL default '0000-00-00 00:00:00',
`menu_modified_date` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`menu_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=48 ;
--
-- Dumping data for table `menu`
--
INSERT INTO `menu` VALUES (1, 1, 'CAREERS', 0, 1, 'index.php/page/index/16', 16, '0000-00-00 00:00:00', '2010-02-05 10:12:23');
INSERT INTO `menu` VALUES (2, 1, 'CONTACT US', 0, 0, 'index.php/page/index/28', 28, '0000-00-00 00:00:00', '2010-02-22 12:21:53');
INSERT INTO `menu` VALUES (3, 1, 'SITEMAP', 0, 0, 'index.php/page/index/49', 49, '0000-00-00 00:00:00', '2010-02-09 04:49:17');
INSERT INTO `menu` VALUES (4, 1, 'UNITED STATES & EUROPE', 1, 1, 'index.php/page/index/43', 43, '0000-00-00 00:00:00', '2010-01-26 09:38:57');
INSERT INTO `menu` VALUES (5, 1, 'INDIA', 1, 2, 'index.php/page/index/44', 44, '0000-00-00 00:00:00', '2010-01-26 09:39:05');
INSERT INTO `menu` VALUES (6, 2, 'HOME', 0, 0, '6', 0, '0000-00-00 00:00:00', '2010-01-22 02:16:35');
INSERT INTO `menu` VALUES (7, 2, 'WHO WE ARE', 0, 0, 'index.php/page/index/52', 52, '0000-00-00 00:00:00', '2010-02-09 02:13:25');
INSERT INTO `menu` VALUES (8, 2, 'WHY CLUTCH GROUP', 0, 0, 'index.php/page/index/51', 51, '0000-00-00 00:00:00', '2010-02-06 07:29:13');
INSERT INTO `menu` VALUES (9, 2, 'OUR SERVICES', 0, 0, 'index.php/page/index/20', 20, '0000-00-00 00:00:00', '2010-02-05 10:12:54');
INSERT INTO `menu` VALUES (10, 2, 'OUR CLIENTS', 0, 0, 'index.php/page/index/21', 21, '0000-00-00 00:00:00', '2010-02-05 10:12:57');
INSERT INTO `menu` VALUES (11, 2, 'RESOURCES', 0, 0, 'index.php/page/index/18', 18, '0000-00-00 00:00:00', '2010-02-05 10:13:01');
INSERT INTO `menu` VALUES (12, 2, 'COMPANY NEWS', 0, 0, 'index.php/page/index/19', 19, '0000-00-00 00:00:00', '2010-02-05 10:13:37');
INSERT INTO `menu` VALUES (13, 2, 'MISSION', 7, 0, 'index.php/page/index/13', 13, '0000-00-00 00:00:00', '2010-02-05 10:13:51');
INSERT INTO `menu` VALUES (14, 2, 'HISTORY', 7, 0, 'index.php/page/index/53', 53, '0000-00-00 00:00:00', '2010-02-05 10:13:56');
INSERT INTO `menu` VALUES (15, 2, 'LEADERSHIP', 7, 0, 'index.php/page/index/22', 22, '0000-00-00 00:00:00', '2010-02-05 10:14:06');
INSERT INTO `menu` VALUES (16, 2, 'AWARDS & RECOGNITIONS', 7, 0, 'index.php/page/index/24', 24, '0000-00-00 00:00:00', '2010-02-05 10:14:12');
INSERT INTO `menu` VALUES (17, 2, 'PARTNERSHIPS', 7, 0, 'index.php/page/index/14', 14, '0000-00-00 00:00:00', '2010-02-05 10:14:21');
INSERT INTO `menu` VALUES (18, 2, 'ORGANIZATIONS', 7, 0, 'index.php/page/index/27', 27, '0000-00-00 00:00:00', '2010-02-05 10:14:30');
INSERT INTO `menu` VALUES (19, 2, 'MANAGEMENT TEAM', 15, 0, 'index.php/page/index/23', 23, '0000-00-00 00:00:00', '2010-02-05 10:15:06');
INSERT INTO `menu` VALUES (20, 2, 'BOARD OF DIRECTORS', 15, 0, 'index.php/page/index/25', 25, '0000-00-00 00:00:00', '2010-02-05 10:15:13');
INSERT INTO `menu` VALUES (21, 2, 'ADVISORY BOARD', 15, 0, 'index.php/page/index/26', 26, '0000-00-00 00:00:00', '2010-02-05 10:15:22');
INSERT INTO `menu` VALUES (22, 2, 'MEET OUR TEAM', 8, 0, 'index.php/page/index/28', 28, '0000-00-00 00:00:00', '2010-02-05 10:15:56');
INSERT INTO `menu` VALUES (23, 2, 'GLOBAL DELIVERY MODEL', 8, 0, 'index.php/page/index/56', 56, '0000-00-00 00:00:00', '2010-02-05 10:16:00');
INSERT INTO `menu` VALUES (24, 2, 'STATE-OF-THE-ART SECURITY', 8, 0, 'index.php/page/index/42', 42, '0000-00-00 00:00:00', '2010-02-05 10:16:05');
INSERT INTO `menu` VALUES (25, 2, 'PROFILES', 22, 0, 'index.php/page/index/54', 54, '0000-00-00 00:00:00', '2010-02-05 10:16:11');
INSERT INTO `menu` VALUES (26, 2, 'LEGAL STAFFING', 9, 0, 'index.php/page/index/41', 41, '0000-00-00 00:00:00', '2010-01-26 09:07:31');
INSERT INTO `menu` VALUES (27, 2, 'DOCUMENT REVIEW', 9, 0, 'index.php/page/index/34', 34, '0000-00-00 00:00:00', '2010-01-26 07:39:02');
INSERT INTO `menu` VALUES (28, 2, 'CONTRACT MANAGEMENT', 9, 0, 'index.php/page/index/33', 33, '0000-00-00 00:00:00', '2010-01-26 07:24:49');
INSERT INTO `menu` VALUES (29, 2, 'COMPLIANCE', 9, 0, 'index.php/page/index/32', 32, '0000-00-00 00:00:00', '2010-01-26 06:49:31');
INSERT INTO `menu` VALUES (30, 2, 'LEGAL RESEARCH', 9, 0, 'index.php/page/index/31', 31, '0000-00-00 00:00:00', '2010-01-26 06:22:56');
INSERT INTO `menu` VALUES (31, 2, 'OFFSHORE REVIEW', 27, 0, 'index.php/page/index/35', 35, '0000-00-00 00:00:00', '2010-01-26 08:04:08');
INSERT INTO `menu` VALUES (32, 2, 'TURN-KEY FACILITIES', 27, 0, 'index.php/page/index/36', 36, '0000-00-00 00:00:00', '2010-01-26 08:16:15');
INSERT INTO `menu` VALUES (33, 2, 'LOW COST MARKETS', 27, 0, 'index.php/page/index/37', 37, '0000-00-00 00:00:00', '2010-01-26 08:21:22');
INSERT INTO `menu` VALUES (34, 2, 'FOREIGN LANGUAGE', 27, 0, 'index.php/page/index/38', 38, '0000-00-00 00:00:00', '2010-01-26 08:32:12');
INSERT INTO `menu` VALUES (35, 2, 'EUROPEAN REVIEW', 27, 0, 'index.php/page/index/39', 39, '0000-00-00 00:00:00', '2010-01-26 08:59:02');
INSERT INTO `menu` VALUES (37, 2, 'DISCOVERY CONSULTING', 27, 0, 'index.php/page/index/40', 40, '0000-00-00 00:00:00', '2010-01-26 09:03:59');
INSERT INTO `menu` VALUES (38, 2, 'CLIENT SUCCESS STORIES', 10, 0, 'index.php/page/index/30', 30, '0000-00-00 00:00:00', '2010-01-26 05:22:52');
INSERT INTO `menu` VALUES (39, 2, 'ETHICS OPINIONS', 11, 0, 'index.php/page/index/29', 29, '0000-00-00 00:00:00', '2010-02-05 10:17:55');
INSERT INTO `menu` VALUES (40, 2, 'PRESS RELEASES', 12, 0, 'index.php/page/index/48', 48, '0000-00-00 00:00:00', '2010-01-27 02:38:26');
INSERT INTO `menu` VALUES (41, 2, 'CLUTCH GROUP IN THE NEWS', 12, 0, 'index.php/page/index/50', 50, '0000-00-00 00:00:00', '2010-02-08 01:15:33');
INSERT INTO `menu` VALUES (42, 2, 'COME SEE US', 12, 0, 'index.php/page/index/55', 55, '0000-00-00 00:00:00', '2010-02-03 02:35:46');
INSERT INTO `menu` VALUES (43, 3, 'TERMS OF USE', 0, 0, 'index.php/page/index/15', 15, '0000-00-00 00:00:00', '2010-02-09 05:32:53');
INSERT INTO `menu` VALUES (44, 3, 'COPYRIGHT NOTICE', 0, 0, 'index.php/page/index/47', 47, '0000-00-00 00:00:00', '2010-02-05 10:18:41');
INSERT INTO `menu` VALUES (45, 3, 'PRIVACY POLICY', 0, 0, 'index.php/page/index/46', 46, '0000-00-00 00:00:00', '2010-02-05 10:18:44');
INSERT INTO `menu` VALUES (46, 3, 'WEBSITE DISCLAIMER', 0, 0, 'index.php/page/index/45', 45, '0000-00-00 00:00:00', '2010-02-05 10:18:47');
INSERT INTO `menu` VALUES (47, 3, 'SITE MAP', 0, 0, 'index.php/page/index/49', 49, '0000-00-00 00:00:00', '2010-02-05 10:18:51');
Wednesday, April 21, 2010
Multi Level Category display
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment