0

Problem:

I have a mysql table with this structure:

CREATE TABLE IF NOT EXISTS `vk_categorieen` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `parent_id` int(10) unsigned DEFAULT NULL,
  `title` varchar(255) NOT NULL,
  `type` varchar(255) NOT NULL,
  `language` enum('nl','fr','en','de') NOT NULL DEFAULT 'nl',
  `user_creation_id` int(10) unsigned NOT NULL,
  `user_update_id` int(10) unsigned DEFAULT NULL,
  `creation_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `update_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `active` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `deleted` tinyint(1) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `title` (`title`(25),`type`(25),`language`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

So each categorie can have a parent category id to build in subcategory functionality.

What I want to achieve =

  • Category 1
    • Subcategory 1
    • Subcategory 2
      • Sub sub category 1
  • Category 2
    • Subcategory 1
    • Subcategory 2
      • Sub sub category 1 ..

Request:

All this values should be in a PHP array.. So the prefixes ( - - ) or ( - - - ) are just text added prefixes. So I have to know when to add the proper text prefix.

I had something in mind with a recursive php function but I just want to check if there is a less intensive mysql function or algoritm to achieve this result.

Sam Vloeberghs
  • 1,082
  • 5
  • 18
  • 29
  • 1
    possible duplicate of [Category Hierarchy (PHP/MySQL)](http://stackoverflow.com/questions/4452472/category-hierarchy-php-mysql) – Shef Sep 11 '11 at 09:01
  • [Managing Hierarchical Data in MySQL](http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/). – Shef Sep 11 '11 at 09:09

0 Answers0