Three tables save articles information:
categories table:
id, lft, rgt, title
lft: left value
rgt: right value
lft and rgt value is Nested Set, example:
root
(0,15)
/ \
/ \
cat1 cat2
(1,6) (7, 14)
/| / | \
/ | / | \
/ | / | \
cat3 cat4 cat5 cat6 cat7
(2,3) (4,5) (8,9)(10,11)(12,13)
article table:
id, title
article_category_map table:
article_id, category_id
How to select all articles from one category and sub-category in MySQL?
I expect:
1、When click cat2, display all articles of cat2 and cat5 and cat6 and cat7.
2、When click cat5 , only display all articles of cat5.
3、Wher click root, display all articles of all categories (include cat1, cat2, cat3,cat4, cat5, cat6, cat7...).