Jump to content

Recommended Posts

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!  :)

Link to comment
https://forums.phpfreaks.com/topic/73004-multiple-level-categories/
Share on other sites

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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.