1

更新的 SQL:环境是 MySQL 5.5。SQL 是通过 phpBB 抽象层生成的,但是当我看到 SQL 时,它看起来是有效的。

SELECT f.*, t.*, p.*, u.*, tt.mark_time AS topic_mark_time, ft.mark_time AS forum_mark_time
FROM (phpbb_posts p CROSS JOIN phpbb_users u CROSS JOIN phpbb_topics t) LEFT JOIN 
phpbb_forums f ON (t.forum_id = f.forum_id) LEFT JOIN phpbb_topics_track tt ON 
(t.topic_id = tt.topic_id AND tt.user_id = 2) LEFT JOIN phpbb_forums_track ft ON 
(f.forum_id = ft.forum_id AND ft.user_id = 2) WHERE p.topic_id = t.topic_id AND 
p.poster_id = u.user_id AND p.post_time > 1380495918 AND p.forum_id IN (7, 6, 5, 3, 4, 2, 1)
AND p.post_approved = 1 ORDER BY t.topic_last_post_time DESC, p.post_time LIMIT
18446744073709551615

错误是:

“on 子句”中的未知列“t.topic_id”[1054]

所有列名都存在。所有表都存在。所有别名都存在。

这是相关的代码:

$sql_array = array(
    'SELECT'    => 'f.*, t.*, p.*, u.*, tt.mark_time AS topic_mark_time, ft.mark_time AS forum_mark_time',

    'FROM'      => array(
        POSTS_TABLE => 'p',
        USERS_TABLE => 'u',
        TOPICS_TABLE => 't'),

    'WHERE'     => "$topics_posts_join_sql
                AND p.poster_id = u.user_id
                $date_limit_sql
                $fetched_forums_str
                $new_topics_sql
                $remove_mine_sql
                $filter_foes_sql
                AND p.post_approved = 1",

    'ORDER_BY'  => $order_by_sql
);

$sql_array['LEFT_JOIN'] = array(
    array(
        'FROM'  => array(FORUMS_TABLE => 'f'),
        'ON'    => 't.forum_id = f.forum_id'
    ),
    array(
        'FROM'  => array(TOPICS_TRACK_TABLE => 'tt', FORUMS_TRACK_TABLE => 'ft'),
        'ON'    => "t.topic_id = tt.topic_id AND tt.user_id  = $user_id"
    ),
        array(
        'FROM'  => array(FORUMS_TRACK_TABLE => 'ft'),
        'ON'    => "f.forum_id = ft.forum_id AND ft.user_id = $user_id"
    )
);

$sql = $db->sql_build_query('SELECT', $sql_array);
4

1 回答 1

0
t.topic_id = TOPICS_TRACK_TABLE.topic_i

是错的。确保它使用正确的别名 tt

于 2013-10-06T22:14:15.890 回答