aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/docs/CHANGELOG.html1
-rw-r--r--phpBB/viewtopic.php15
2 files changed, 11 insertions, 5 deletions
diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html
index 61b4caf1b0..b06334bd9a 100644
--- a/phpBB/docs/CHANGELOG.html
+++ b/phpBB/docs/CHANGELOG.html
@@ -123,6 +123,7 @@
<li>[Fix] Language typos/fixes. (Bug #27625, #30755)</li>
<li>[Fix] Added missing terms parameter to search pagination. (Bug #34085)</li>
<li>[Change] Do not use the topics posted table when performing an egosearch.</li>
+ <li>[Fix] Wrong table order in query obtaining posts if post id given.</li>
</ul>
diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php
index 8db6ed1ebd..fac6476a55 100644
--- a/phpBB/viewtopic.php
+++ b/phpBB/viewtopic.php
@@ -178,12 +178,18 @@ if ($view && !$post_id)
$sql_array = array(
'SELECT' => 't.*, f.*',
- 'FROM' => array(
- FORUMS_TABLE => 'f',
- TOPICS_TABLE => 't',
- )
+ 'FROM' => array(FORUMS_TABLE => 'f'),
);
+// The FROM-Order is quite important here, else t.* columns can not be correctly bound.
+if ($post_id)
+{
+ $sql_array['FROM'][POSTS_TABLE] = 'p';
+}
+
+// Topics table need to be the last in the chain
+$sql_array['FROM'][TOPICS_TABLE] = 't';
+
if ($user->data['is_registered'])
{
$sql_array['SELECT'] .= ', tw.notify_status';
@@ -226,7 +232,6 @@ if (!$post_id)
else
{
$sql_array['WHERE'] = "p.post_id = $post_id AND t.topic_id = p.topic_id" . ((!$auth->acl_get('m_approve', $forum_id)) ? ' AND p.post_approved = 1' : '');
- $sql_array['FROM'][POSTS_TABLE] = 'p';
}
$sql_array['WHERE'] .= ' AND (f.forum_id = t.forum_id';