我想输出类别名称,每个类别中的子类别名称,以及每个类别和每个子类别中的文章。
输出应该是 HTML 中的 in<ul>
和 inner<ul>
标记。
以下是输出的样子:
我有这 5 张桌子:
table_article_categories(articlecat_id, parent_id, articlecat_status, ...)
table_article_to_article_categories(articlecat_id, articles_id)
table_articles(articles_id, articles_status, ...)
table_articles_description(articles_id, language_id, articles_heading_title, ...)
table_article_categories_description(articlecat_id, articlecat_name, language_id, ...)
到目前为止,我已经制作了这个 SQL:
SELECT
ac.parent_id,
ac.articlecat_id,
a.articles_id,
ad.articles_heading_title AS article_name,
acd.articlecat_name
FROM
table_article_categories AS ac
LEFT JOIN
table_article_to_article_categories AS atac
ON
atac.articlecat_id = ac.articlecat_id
LEFT JOIN
table_articles AS a
ON
a.articles_id = atac.articles_id
AND
a.articles_status = 1
LEFT JOIN
table_articles_description AS ad
ON
ad.articles_id = a.articles_id
AND
ad.language_id = 1
INNER JOIN
table_article_categories_description AS acd
ON
acd.articlecat_id = ac.articlecat_id
AND
acd.language_id = 1
WHERE
ac.parent_id = 99 # --- This is the root article-categori-id ---
AND
ac.articlecat_status = 1
AND
ac.articlecat_id != 77 # --- This is an excluded article-categori-id ---
ORDER BY
acd.articlecat_name ASC,
article_name ASC