数据库结构类似于:
CREATE TABLE `newfrog_category` (
  `category_id` tinyint(4) NOT NULL,
  `parent_id` tinyint(4) NOT NULL,
  `name` varchar(255) NOT NULL,
  `position` tinyint(4) NOT NULL,
  `level` tinyint(4) NOT NULL,
  `is_active` tinyint(4) default '1',
  `children` tinyint(4) default '1',
  PRIMARY KEY (`category_id`),
  UNIQUE KEY `category_id` (`category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;我想把数据库的数据处理然后放进数组,
数组格式类似于
array ( 'category_id' => '1', 'parent_id' => '0', 'name' => 'Root Catalog', 'position' => '0', 'level' => '0', 'children' => array ( 0 => array ( 'category_id' => '2', 'parent_id' => '1', 'name' => 'Default Category', 'is_active' => '1', 'position' => '1', 'level' => '1', 'children' => array ( 0 => array ( 'category_id' => '3', 'parent_id' => '2', 'name' => 'Apple Accessories', 'is_active' => '1', 'position' => '1', 'level' => '2', 'children' => array ( 0 => array ( 'category_id' => '4', 'parent_id' => '3', 'name' => 'Ipad Accessories', 'is_active' => '1', 'position' => '1', 'level' => '3', 'children' => array ( 0 => array ( 'category_id' => '109', 'parent_id' => '4', 'name' => 'Cables & Docks', 'is_active' => '1', 'position' => '1', 'level' => '4', 'children' => array ( ), )思路是每个分类可能会有子类,子类的parent_id就是父类的category_id