Good day. There is a base with structure
CREATE TABLE `catalog_city` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `parent_id` int(8) NOT NULL DEFAULT '0', `name` varchar(250) NOT NULL DEFAULT '', `level` tinyint(2) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; INSERT INTO `catalog_city` VALUES ('1', '0', 'Россия', '0'); INSERT INTO `catalog_city` VALUES ('2', '0', 'Беларусь', '0'); INSERT INTO `catalog_city` VALUES ('3', '2', 'Минск2', '0'); INSERT INTO `catalog_city` VALUES ('4', '1', 'Минск2', '0'); In fact, the number of entries is measured by a thousand, and the level of attachment is not known. It is required to affix the level of attachment to the level column (from 0 to the last nesting). How to do it in a loop?