php 处理数据 到数组当中

shijie8332899 2011-08-31 10:17:08
数据库结构类似于:
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
...全文
96 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2011-08-31
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20110728/15/eadffb68-5eb6-40d8-9ec1-2bc439f45322.html
wood87654321 2011-08-31
  • 打赏
  • 举报
回复
他是想直接把数据表读成树结构
tai_zi_ye 2011-08-31
  • 打赏
  • 举报
回复
弱弱的问一下 LZ打算做几维数组
xieleri 2011-08-31
  • 打赏
  • 举报
回复
楼主的想法是不是想做成无限分类的
shijie8332899 2011-08-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 tai_zi_ye 的回复:]

弱弱的问一下 LZ打算做几维数组
[/Quote]
无限级别的

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧