MySQL查询以检索完整URL段 [英] MySQL Query to retrieve full URL slug

查看:95
本文介绍了MySQL查询以检索完整URL段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个问题!

我有一个MySQL表,它存储网站各个页面上的所有内容。假设有三个字段,id(int),permalink(varchar)和parent(int)( parent 是它的父页面的id。

I have a MySQL table which stores all content on the various pages of a site. Let's say there's three fields, id(int), permalink(varchar) and parent(int)(. parent is the id of it's parent page.

我需要一个查询来构建一个页面的完整URL,我猜使用CONCAT。我有两个级别的工作正常,但不能找出一种方法使它多个级别的缩放; / root / level1 / level2 / etc。

I need a query that will build a full URL of a page, I'm guessing using CONCAT. I have it working fine for two levels, but can't figure out a way to make it scale for multiple levels; /root/level1/level2/ etc.

这是我到目前为止所有的。

Here's what I have so far.

SELECT 
CONCAT(
(SELECT permalink FROM content WHERE id = 2 LIMIT 1), # id = parent
"/", 
(SELECT permalink FROM content WHERE id = 11 LIMIT 1)) as full_url

任何帮助,非常感谢!

Any help, greatly appreciated!

推荐答案

这将是一个递归查询,你必须在服务器上使用一个存储过程strong> avaiable in MySql @Claude)。

That would be a recursive query, you have to use a stored procedure on the server (Which are avaiable in MySql @Claude).

这篇关于MySQL查询以检索完整URL段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆