尝试做一个论坛系统优化,在一个查询中选择所有最后的海报并将它们存储在一个数组中。事情是数据库正在返回意外的结果
PHP 版本 5.3.13
MySQL 版本 5.1.63
$getPosts = $dB->fetch('
SELECT
post_id, post_poster_id, post_topic_id, post_time,
COUNT(post_id) as count
FROM forum_posts
WHERE post_topic_id IN (
SELECT topic_id
FROM forum_topics
WHERE topic_forum_id = ' . $forum_id . '
)
GROUP BY post_topic_id
ORDER BY post_time DESC
');
foreach($getPosts as $lastPoster)
{
$lastPosts[$lastPoster['post_topic_id']] = $lastPoster;
}