The approach this user made on this question for the database structure works fine. However, thinking in a relational database approach, what is the best approach for a multi-level category database?
VERY SIMPLE AND EFFECTIVE
We simply do a recursive association.
id title content parent_id
==============================================
1 item1 NULL NULL
2 item2 NULL 1
3 item3 abcd 2
4 item4 efgh 2
In this example:
item1 is the first level (see that the parent_id is NULL).
item2 is a second level option from item1 (see that the parent_id is 1 and the content is NULL making this another drill down option only).
item3 and item4 are content from item2 (see that parent_id is 2 and the content is NOT null).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With