php分类列表怎么查数据库,数据库分类查询有关问题

数据库分类查询问题

有一个分类表,结构是这样的

id name father categoryorder

1 A 0

2 B 0

3 A.1 1

4 A.2 1

5 A.1.a 3

6 A.1.b 3

7 B.1 2

categoryorder我想用于分类的排序,想实现把分类以树形显示的功能,categoryorder应该怎么设计?

A

--A.1

----A.1.a

----A.1.b

--A.2

B

--B.1

在PHP上应该怎么实现?

------解决方案--------------------

LZ如果你的"分类表"是数据库表,你应该考虑现在SQL做处理。

按你的思路,你可以建一个字段叫"系列"之类的 根据这个系列用order by分组排序

SELECT * from good

ORDER BY series

e39a3ce4f6192b4db7eac917f6c62c37.png

------解决方案--------------------

static function GetTree($depth, $parentID, $nodeID)

{

$str = "";

$nodes = D_node::GetListAll("where parentid=" . $parentID . "", "orderflag desc");

if (count($nodes) > 0) {

foreach ($nodes as $node) {

$str .= self::GetPrefixString($depth) . $node->nodename;

$str .= self::GetTree($depth + 1, $node->id, $nodeID);

}

}

return $str;

}

static function GetPrefixString($depth)

{

$str = "--";

for ($i = 0; $i < $depth; $i++) {

$str .= "--";

}

return $str;

}

相关文章

相关视频

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值