feri_soft Posted October 12, 2007 Share Posted October 12, 2007 Hello, i am having problems to do unlimited multiple level categories. I have managed to create them in a tree menu and i have also managed to get them work in unlimited chained selects via jQuery but i want them to be just like xcart: Please go to http://www.x-cart.com/demo/admin/home.php click login and try add a new product for example. You will see a multiple select box like: parent parent::child parent::child::child1 parent::child1::child2 or: parent::child parent::child::child1 parent::child::child1::child2 but i suppose the second will provide too long values. I have the following code now: http://pastebin.com/f66a1fb90 with the following db structure: CREATE TABLE `category` ( `id` int(11) NOT NULL auto_increment, `name` varchar(100) character set cp1251 collate cp1251_bulgarian_ci NOT NULL, `parent` int(11) NOT NULL, `place` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=cp1251 AUTO_INCREMENT=7 ; -- -- Dumping data for table `category` -- INSERT INTO `category` VALUES (1, 'asdasd', 0, 1); INSERT INTO `category` VALUES (2, 'asdasd1', 1, 2); INSERT INTO `category` VALUES (3, 'rrrrrr', 2, 3); INSERT INTO `category` VALUES (4, 'eeeeee', 3, 4); INSERT INTO `category` VALUES (5, 'ssss', 2, 5); INSERT INTO `category` VALUES (6, 'eeee', 2, 6); this is modified code i found on the net. Please help me with this because i just keep getting different errors. Now the output of the code is: asdasd - asdasd::asdasd1 - asdasd1::rrrrrr - rrrrrr::eeeeee - asdasd1::ssss - asdasd1::eeee which is pretty close to what i need but i also need in front of rrrrr to have asdasd1 again. I need it this way so i can specify more than one cat for a product and i like this structure more than the one i first created - the old fashioned tree menu style within the select. I will be glad to hear any suggestions! Quote Link to comment https://forums.phpfreaks.com/topic/73004-multiple-level-categories/ Share on other sites More sharing options...
feri_soft Posted October 13, 2007 Author Share Posted October 13, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/73004-multiple-level-categories/#findComment-368500 Share on other sites More sharing options...
Barand Posted October 13, 2007 Share Posted October 13, 2007 try function cats($parent, $prefix='') { $sql = "SELECT id, name FROM category WHERE parent = $parent"; $res = mysql_query($sql); while (list($id, $name) = mysql_fetch_row($res)) { echo $prefix . $name . '<br>'; cats ($id, $prefix . $name . '::'); } } cats(0); Quote Link to comment https://forums.phpfreaks.com/topic/73004-multiple-level-categories/#findComment-368513 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.