gpt4 book ai didi

php mysql 查询 - 添加更多字段时文档为空

转载 作者:行者123 更新时间:2023-11-30 01:15:12 25 4
gpt4 key购买 nike

我有一个运行良好的 mysql 查询:

$query = "SELECT
USER.USER_ID, NAME, SURNAME, EMAIL, STATUS, PHOTO
FROM FRIENDLIST, USER, USER_PROFILE
WHERE FRIENDLIST.FRIEND_ID = ANY (
SELECT FRIEND_ID FROM FRIENDLIST WHERE USER_ID=".$userID."
)
AND APPROVED='YES'
AND USER.USER_ID=FRIENDLIST.FRIEND_ID
AND USER.USER_ID=USER_PROFILE.USER_ID
UNION
SELECT
USER.USER_ID, NAME, SURNAME, EMAIL, STATUS, PHOTO FROM FRIENDLIST, USER, USER_PROFILE
WHERE FRIENDLIST.FRIEND_ID = " . $userID . "
AND APPROVED = 'YES'
AND USER.USER_ID=FRIENDLIST.USER_ID
AND USER.USER_ID=USER_PROFILE.USER_ID";

当我在查询中添加更多字段时,出现“文档为空”错误。

$query = "SELECT
USER.USER_ID, NAME, SURNAME, EMAIL, STATUS, PHOTO, gender, cposition, rinterest, about
FROM FRIENDLIST, USER, USER_PROFILE
WHERE FRIENDLIST.FRIEND_ID = ANY (
SELECT FRIEND_ID FROM FRIENDLIST WHERE USER_ID=" . $userID . "
)
AND APPROVED='YES'
AND USER.USER_ID=FRIENDLIST.FRIEND_ID
AND USER.USER_ID=USER_PROFILE.USER_ID
UNION
SELECT
USER.USER_ID, NAME, SURNAME, EMAIL, STATUS, PHOTO
FROM FRIENDLIST, USER, USER_PROFILE
WHERE FRIENDLIST.FRIEND_ID = ".$userID."
AND APPROVED='YES'
AND USER.USER_ID=FRIENDLIST.USER_ID
AND USER.USER_ID=USER_PROFILE.USER_ID";

新字段属于USER_PROFILE表。

最佳答案

您使用的是 UNION,因此两个 SELECT 查询必须具有完全相同的列数。否则,您的查询将失败,并且可能会出现您所看到的错误。此错误消息可能还表明未检查查询结果是否有错误或失败。

如果代码格式正确,这将更容易发现。允许(并建议)在 SQL 查询中使用 Enter。

关于php mysql 查询 - 添加更多字段时文档为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19135238/

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