开发者

Making a parent-child hierachy of msg records saved into mysql?

How could I store messages data into a database so that I could print it as parent child nodes in an unordered list? Each root node could have 2 child(depth) i.e. like grand father, father, & children. e.g.

 -vehicle
   -public
     -Lorry //Lorry is lost node for root vehicle,           

The fields currently I store about a msg are ID(PK),name,msg,msg_id(unique). I am thinking like if each record could have a 'parent' field that would contain 'msg_id' of the record it is a child of. Then thi开发者_开发百科s information could be used to retrieve all parents & all child nodes of parents. And then those could be printed in a parent child hierarchy in an unordered list.


For each node (row in the database) store a reference to the parent.

Example:

| name    | id      | parent_id
------------------------------
| vehicle | 1       | null
| public  | 2       | 1
| Lorry   | 3       | 2

This is the easiest and most straight-forward approach.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜