+ -
当前位置:首页 → 问答吧 → php 处理数据 到数组当中

php 处理数据 到数组当中

时间:2011-08-31

来源:互联网

数据库结构类似于:
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

作者: shijie8332899   发布时间: 2011-08-31

弱弱的问一下 LZ打算做几维数组

作者: tai_zi_ye   发布时间: 2011-08-31

相关阅读 更多