Reputation: 33
My goal is to achieve a list of parent categories from a nested category the easiest way. Say if I had a site that sold a variety of different products, one of which is a quad core pentium. A feature that I'd be able to display on my webpage is as follows:
Electronics > Computers > CPU's > Intel > Intel Quad Core
The category table that I had in mind is:
id, parent_id, description
Doing a recursive process on the parent_id seems tedious. Is there a preferred way of doing this? Thank you.
Upvotes: 3
Views: 1493
Reputation: 96159
Take a look at Managing Hierarchical Data in MySQL.
The part you're probably interested in most right now is this:
Retrieving a Single Path
With the nested set model, we can retrieve a single path without having multiple self-joins.
Upvotes: 6