Hello,
I found this tutorial http://sqllessons.com/categories.html and I want to use the described method as it’s better than a recursive call but I have two problems:
-
How will I know the deepest level? In some page I may have 2 and in another I may have 20. Am I missing something or this method can be used only if you know the deepest level prior runtime!?
-
I have a multilingual database design, how can I change the queries to work with my table design below:
CREATE TABLE `categories` (
`id` int(11) NOT NULL,
`position` int(11) DEFAULT NULL,
`parent_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `parent_id_fk` (`parent_id`),
CONSTRAINT `categories_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `categories` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `categories_locale` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`slug` varchar(100) NOT NULL DEFAULT '',
`name` varchar(40) NOT NULL DEFAULT '',
`category_id` int(11) NOT NULL,
`locale_id` smallint(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `locales` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`code` char(2) DEFAULT NULL,
`name` varchar(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
Your help would be greatly appreciated.