我收到错误查询失败:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 5 行“5,7,6,9,13 ORDER BY n.date DESC”附近使用的正确语法。任何人都可以指出问题所在吗?谢谢
$news_query = 'SELECT u.id as userId, u.username, n.id as newsId, n.action, n.date
FROM newsfeed as n
JOIN users as u on n.userId = u.id
WHERE
userId in '.implode(',', array_map('intval', $myfriends)).' &&
userId == :myId // posts by me
ORDER BY n.date DESC
';
$tuple = implode(',', array_map('intval', $myfriends));
$news_query = <<< SQL
SELECT
u.id AS userId,
u.username,
n.id AS newsId,
n.action,
n.date
FROM
newsfeed AS n
JOIN
users AS u ON n.userId = u.id
WHERE
userId IN ($tuple) AND
userId = :myId
ORDER BY
n.date DESC
SQL;
您还应该限定userId领域中的WHERE条款;即放u. or n.放在它的前面,这样就不会产生歧义。