gpt4 book ai didi

php - 为什么 MySQL 语句被忽略?

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

为什么是n.author='$host[id]'被忽略?

$host[id]=5;
SELECT
n.id,n.name,n.text,
r.title,
COUNT(c.news_id) comments
FROM news n LEFT JOIN rub r
ON
r.news_id=n.id
LEFT JOIN comments c
ON
n.id = c.news_id AND c.status='1' AND n.author='$host[id]'
GROUP BY n.id
ORDER BY n.id DESC LIMIT 10

我只需要 'news'.'author'=$host[id] 的行,但执行此查询我从表中获取了所有新闻。为什么会发生这种情况?

最佳答案

$host[id]=5;

SELECT n.id,n.name,n.text, r.title, COUNT(c.news_id) comments
FROM news n
LEFT JOIN rub r ON r.news_id = n.id
LEFT JOIN comments c ON c.news_id = n.id AND c.status = '1'
WHERE n.author = '$host[id]'
GROUP BY n.id
ORDER BY n.id DESC LIMIT 10

关于php - 为什么 MySQL 语句被忽略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20933347/

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