我的类别表设计如下如何显示类别,分类别和子子类别 - 笨
我有三个层次类别
- 父
- 孩子 的
- 子小孩
如何以下列方式显示它们?
(SELECT * FROM类别):我得到下面的数组如下
Array
(
[0] => stdClass Object
(
[category_id] => 1
[category_slug] =>
[category_glyphicon] => live glypicon
[category_name] => Live
[is_parent] => 0
[is_child] => 0
[is_sub_child] => 0
[rf_flag] => 0
[status] => 1
[category_description] =>
[created_on] => 2015-09-04 10:47:54
[updated_on] => 2015-09-05 22:48:01
)
[1] => stdClass Object
(
[category_id] => 2
[category_slug] =>
[category_glyphicon] => dddd
[category_name] => work
[is_parent] => 0
[is_child] => 0
[is_sub_child] => 0
[rf_flag] => 0
[status] => 1
[category_description] =>
[created_on] => 2015-09-04 11:41:18
[updated_on] => 2015-09-04 11:11:18
)
[2] => stdClass Object
(
[category_id] => 3
[category_slug] =>
[category_glyphicon] => mmm
[category_name] => enjoy
[is_parent] => 0
[is_child] => 0
[is_sub_child] => 0
[rf_flag] => 0
[status] => 1
[category_description] =>
[created_on] => 2015-09-04 11:41:52
[updated_on] => 2015-09-04 11:12:51
)
[3] => stdClass Object
(
[category_id] => 4
[category_slug] =>
[category_glyphicon] => mmm
[category_name] => for sale
[is_parent] => 1
[is_child] => 0
[is_sub_child] => 0
[rf_flag] => 0
[status] => 1
[category_description] =>
[created_on] => 2015-09-04 11:42:59
[updated_on] => 2015-09-04 11:12:59
)
[4] => stdClass Object
(
[category_id] => 5
[category_slug] =>
[category_glyphicon] => ccccc
[category_name] => for rent
[is_parent] => 1
[is_child] => 0
[is_sub_child] => 0
[rf_flag] => 0
[status] => 1
[category_description] =>
[created_on] => 2015-09-05 12:13:48
[updated_on] => 2015-09-04 11:43:48
)
[5] => stdClass Object
(
[category_id] => 6
[category_slug] =>
[category_glyphicon] => sss
[category_name] => villas
[is_parent] => 4
[is_child] => 1
[is_sub_child] => 0
[rf_flag] => 0
[status] => 1
[category_description] =>
[created_on] => 2015-09-05 12:14:57
[updated_on] => 2015-09-04 11:44:57
)
)
官方笨论坛主题基本上,你有处理分层数据时采用两种方式/两种数据库设计:http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/并且,t您可以检查一些类别显示的解决方案:http://stackoverflow.com/questions/3116330/recursive-categories-with-a-single-query,http://stackoverflow.com/questions/2871861/how -to-build-unlimited-level-of-menu-through-php-and-mysql#3368622 – sinisake
是高效的邻接表模型吗? –
呃......对我来说比较容易,而且我迄今为止使用过它,没有尝试第二种模式。有更多经验的人可能可以提供一些关于它的信息...此外,我通常设置一个额外的列(位置)来应用自定义命令... – sinisake