开发者

PHP shop - unlimited tree of categories [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

php / Mysql best tree structure

I'm creating a shop script and I have a little problem. I need to create a php array of tree shop categories, for example:

my mysql table (categories):

'id', 'category_id', 'parentCategory_id'  
1, 11, 0  
2, 12, 0  
3, 13, 12  
4, 14, 12  
5, 15, 14  
6, 16,开发者_JS百科 0

if parentCategory_id==0 there is no parent. PHP array should look like this: http://i.imgur.com/LPAns.jpg.

But I'm not convinced to do it with this method, so if you have any suggestion or solution please help me.

EDIT: Maybe I should display categories in xml? how I can do it? I havent any ideas...


As Konerak says this datamodel allows for unlimited levels of categories. What I would suggest is to drop the id column. The category_id column is the natural primary key.

Note that this holds true only if the categories are allowed to have one parent. Otherwise a separate table will be needed.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜