使用语言 table 在一个 SQL 查询中获取所有 parent 行的面包屑

Getting breadcrumbs all parent rows in one SQL query with languages table

你好,我需要在一个 mysql 查询中获取所有面包屑链接(url,文本)。 使用当前语言,table pages_text 中的语言翻译(文本)。 table 页中的 Ulr 和 parent_id。

所以我需要使用当前语言的所有 parents 行。

我有 2 table

1: 页数

身份证名parent_idurl

1 Home       0        (some url)
2 About      1        (some url)
3 Contact    1        (some url)
4 Legal      2        (some url)
5 Privacy    4        (some url)
6 Products   1        (some url)
7 Support    1        (some url)

2: pages_text

身份证名pages_idlanguages_id

1 Main                 0        2
2 About                1        1
3 (different languges) 1        3
4 (different languges) 2        4
5 (different languges) 4        2
6 (different languges) 1        1
7 (different languges) 1        2

有一些工作代码,其中一个 table 已满 parents 行。

你能帮我修改这段代码 2 table 秒吗?

id  name    parent_id
---------------------------
1   Home        0
2   About       1
3   Contact     1
4   Legal       2
5   Privacy     4
6   Products    1
7   Support     1



SELECT T2.id, T2.name
    FROM (
        SELECT
            @r AS _id,
            @p := @r AS previous,
            (SELECT @r := parent_id FROM table1 WHERE id = _id) AS parent_id,
            @l := @l + 1 AS lvl
        FROM
            (SELECT @r := 5, @p := 0, @l := 0) vars,
            table1 h
        WHERE @r <> 0 AND @r <> @p) T1
    JOIN table1 T2
    ON T1._id = T2.id
    ORDER BY T1.lvl DESC

谢谢。

使用语言 2 表的工作代码全链面包屑:

SELECT T2.id, T2.name, T3.plates_title
    FROM (
        SELECT
            @r AS _id,
            @p := @r AS previous,
            (SELECT @r := parent_id FROM pages WHERE id = _id) AS parent_id,
            @l := @l + 1 AS lvl
        FROM
            (SELECT @r := 121, @p := 0, @l := 0) vars,
            pages h
        WHERE @r <> 0 AND @r <> @p) T1
    JOIN pages T2
    ON T1._id = T2.id
    JOIN pages_text T3 
    ON T1._id = T3.pages_id where T3.languages_id = 1
    ORDER BY T1.lvl DESC