PHP - CMS 站点地图...使用了太多查询/如何改进它?

发布于 2024-08-22 10:13:57 字数 218 浏览 8 评论 0原文

看看这个,抱歉外部链接,但它在这里看起来很难看(也许我很愚蠢地正确格式化它)^^

http:// /codepad.org/GiOgLhNE

如果您想与我交谈,请加入我的 irc 频道

tinyurl.com/ylsf7ef(网络聊天)

Check this out, sorry for external link but it looks ugly here (maby iam to stupid to format it correct) ^^

http://codepad.org/GiOgLhNE

Join my irc channel if you like to talk to me

tinyurl.com/ylsf7ef (webchat)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墟烟 2024-08-29 10:13:57

使用联接。

为了更清楚起见,我删除了一些 where 条件

SELECT
  c.id as c_id, 
  c.alias as c_alias,
  c.title as c_title,
  sc.id as sc_id,
  sc.alias as sc_alias,
  sc.title as sc_title,
  a.alias as a_alias,
  a.title as a_title,
  sa.alias as sa_alias,
  sa.title as sa_title
FROM
  categories c
LEFT JOIN
  articles a
ON
  c.id = a.category_id
LEFT JOIN
  categories sc
ON
  c.id = sc.parent_id
LEFT JOIN
  articles sa
ON
  sc.id = sa.category_id
ORDER BY
  c.rank,
  a.rank,
  sc.rank,
  sa.rank

编辑:据我所知,这里的情况并非如此,但如果您想检索一些无限深度的元素,您可能需要查看 一种在关系数据库中存储强分层数据的方法

Use joins.

I removed some where conditions for more clarity

SELECT
  c.id as c_id, 
  c.alias as c_alias,
  c.title as c_title,
  sc.id as sc_id,
  sc.alias as sc_alias,
  sc.title as sc_title,
  a.alias as a_alias,
  a.title as a_title,
  sa.alias as sa_alias,
  sa.title as sa_title
FROM
  categories c
LEFT JOIN
  articles a
ON
  c.id = a.category_id
LEFT JOIN
  categories sc
ON
  c.id = sc.parent_id
LEFT JOIN
  articles sa
ON
  sc.id = sa.category_id
ORDER BY
  c.rank,
  a.rank,
  sc.rank,
  sa.rank

EDIT: As far as I can see, this is not the case here, but if you want to retrieve some unlimited depth elements, you might want to look at a way to store strong hierarchical data in a relational database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文