gpt4 book ai didi

php - MySQL编码问题

转载 作者:行者123 更新时间:2023-11-30 23:40:17 27 4
gpt4 key购买 nike

user_id = '". $user_id . "' 时,如何使用 users_friends.user_id 加入 users

friend_id = '". $user_id . "' 时,将 users 加入 users_friends.friend_id

if user_id = '". $user_id . "'

INNER JOIN users ON users_friends.user_id = users.user_id

if friend_id = '". $user_id . "'

INNER JOIN users ON users_friends.friend_id = users.user_id

当前的 MySQL 代码。

SELECT COUNT(user_id) as friends
FROM users_friends
WHERE (user_id = '" . $user_id . "'
OR friend_id = '" . $user_id . "')
AND friendship_status = '1'

最佳答案

 (SELECT * FROM users_friends JOIN users ON users.user_id = users_friends.friend_id 
WHERE users_friends.friend_id = '" . $user_id . "')
UNION
(SELECT * FROM users_friends JOIN users ON users.user_id = users_friends.user_id
WHERE users_friends.user_id = '" . $user_id . "')

类似这样的东西可能会起作用。

当您查看 user_friends 表时,您应该使用它来连接 users 表。

关于php - MySQL编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3933332/

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