I created two tables and uploaded it to trusted imgur.com to show you an example:
https://i.stack.imgur.com/viIsR.jpg
// EDIT looks like imgur is down, uploaded to another site: http://images.tinypic.pl/i/00761/0ies71okcyxd.png
As it is in the example above, you see, that
- PANTIES
- CORSET
- SOCKS
- PAJAMA
belongs to parent 5, which belongs to category 5, it means to UNDERWEAR and that category belongs to parent 1, which means that it belong to category 1 called CLOTHES.
I'm reading examples on sites like these below:
www.phpro.org/tutorials/Managing-Hierarchical-Data-with-PHP-and-MySQL.html
mysql hierarchy storage with large trees
http://www.slideshare.net/billkarwin/models-for-hierarchical-data
https://www.percona.com/blog/2011/02/14/moving-subtrees-in-closure-table/
https://pragprog.com/book/bksqla/sql-antipatterns
What is the most efficient/elegant way to parse a flat table into a tree?
and I still can not figure out how to display path of:
- ALL CLOTHES,
- ALL UNDERWEAR (PANTIES, CORSET, SOCKS, PAJAMA).
I can only display for example:
PAJAMA
SELECT t.path FROM thumbnails t LEFT JOIN categories c ON t.category = c.category WHERE t.category = 9
where 9 = PAJAMA