gpt4 book ai didi

mysql - 如何将url字符串添加到mysql查询?

转载 作者:行者123 更新时间:2023-11-29 05:12:38 26 4
gpt4 key购买 nike

我使用以下代码创建了一个前端表。它工作得很好。但我想做的是根据他们的 user_id 添加指向成员个人资料的链接。我们通过访问 http://example.com/profile/?profile=642 查看成员(member)资料(642 是 user_id)所以,我想在我的表中的 m4.user_id 前面添加“http://example.com/profile/?profile=”。任何帮助将不胜感激。

SELECT
DISTINCT
u1.id,
u1.user_login,
u1.user_registered,
u1.user_email,
u1.user_url,
m1.meta_value AS firstname,
m2.meta_value AS lastname,
m3.meta_value AS mepr_region,
m4.user_id,
t1.status,
t2.expires_at
FROM wp_acfzia_users u1
JOIN wp_acfzia_usermeta m1 ON (m1.user_id = u1.id AND m1.meta_key = 'first_name')
JOIN wp_acfzia_usermeta m2 ON (m2.user_id = u1.id AND m2.meta_key = 'last_name')
JOIN wp_acfzia_usermeta m3 ON (m3.user_id = u1.id AND m3.meta_key = 'mepr_region')
JOIN wp_acfzia_usermeta m4 ON (m4.user_id = u1.id)
JOIN wp_acfzia_mepr_transactions t1 ON (t1.id = u1.id)
JOIN wp_acfzia_mepr_transactions t2 ON (t2.id = u1.id)
WHERE m3.meta_value = 'aimga-south'

最佳答案

使用Mysql的CONCAT函数连接两个字符串:

SELECT
m4.user_id,
CONCAT('http://example.com/profile/?profile=', m4.user_id) as profile_url
...

Mysql 会自动将您的 id 整数转换为要连接的字符串。

关于mysql - 如何将url字符串添加到mysql查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37282934/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com