php - SQL 错误访问论坛部分“查看您的帖子”
问题描述
我在我的 PHPBB 论坛中遇到了一个小问题。我擅长HTML、CSS和JS,但我对SQL一无所知。当我点击“查看您的帖子”时,会发生以下错误。
SQL ERROR [ mysqli ]
Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'winx_forum.p.post_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by [1055]
SQL
SELECT DISTINCT SQL_CALC_FOUND_ROWS p.post_id FROM winx_topics t, winx_posts p WHERE p.poster_id = '2' AND t.topic_id = p.topic_id GROUP BY t.topic_id, t.topic_last_post_time ORDER BY t.topic_last_post_time DESC
BACKTRACE
FILE: (not given by php)
LINE: (not given by php)
CALL: msg_handler()
FILE: [ROOT]/includes/db/dbal.php
LINE: 757
CALL: trigger_error()
FILE: [ROOT]/includes/db/mysqli.php
LINE: 182
CALL: dbal->sql_error()
FILE: [ROOT]/includes/search/fulltext_native.php
LINE: 1009
CALL: dbal_mysqli->sql_query()
FILE: [ROOT]/search.php
LINE: 540
CALL: fulltext_native->author_search()
解决方案
错误信息很清楚,SELECT 中的每一列都必须在 GROUP BY 中,并且没有聚合函数
您的SQL_CALC_FOUND_ROWS已弃用。所以试试 COUNT
进一步的逗号分隔表也是过去的想法,今天我们使用Join。
SELECT
COUNT(DISTINCT p.post_id)
FROM
winx_topics t INNER JOIN
winx_posts p ON t.topic_id = p.topic_id
WHERE
p.poster_id = '2'
GROUP BY t.topic_id , t.topic_last_post_time
ORDER BY t.topic_last_post_time DESC