我的SQL查询/ PDO准备好的语句不起作用

时间:2020-06-01 23:14:52

标签: php sql pdo

我目前正在网站的论坛方面工作,主页应显示子论坛列表,最新主题/帖子,发布者和时间。

这是当前代码:

$getTopics = $db->prepare("
SELECT ForumTopic.*, 
       (SELECT GROUP_CONCAT(forum_threads.title, 'SEX', User.Username, 'SEX', User.Admin, 'SEX', forum_threads.date) 
        FROM forum_threads 
        JOIN User ON forum_threads.author_id = User.ID 
        WHERE forum_threads.id = (
            CASE WHEN ForumTopic.LastPostReplyID = 1 
            THEN ForumTopic.LastPostThreadID 
            ELSE (
                SELECT thread_id 
                FROM forum_replies 
                WHERE id = ForumTopic.LastPostReplyID) 
            END)) AS LastPostInfo 
FROM ForumTopic 
WHERE ForumTopic.CategoryID = 1 
ORDER BY ForumTopic.ID ASC");
$getTopics->execute();

if ($getTopics->rowCount() == 0) {

    echo '
    <div class="content-box is-rounded-bottom">
        No topics found.
    </div>
    ';

} else {

    foreach ($getTopics as $key => $gT) {

        if ($key > 0) {
            echo '<hr>';
        }

        echo '
        <div class="forum-topic">
            <div class="row">
                <div class="col-sm-7 align-self-center">
                    <div class="topic-title"><a href="'.$serverUrl.'/forum/topic?id='.$gT->ID.'">'.htmlentities($gT->Name).'</a></div>
                    <div class="topic-description">'.htmlentities($gT->Description).'</div>
                </div>
                <div class="col-sm-1 text-center align-self-center">
                    <div>0</div>
                </div>
                <div class="col-sm-1 text-center align-self-center">
                    <div>0</div>
                </div>
                <div class="col-sm-3 text-right align-self-center">
                ';

                    if ($gT->LastPostThreadID != 1 && !empty($gT->LastPostInfo)) {

                        $PostInfo = explode('SEX', $gT->LastPostInfo);
                        $ThreadName = LimitTextByCharacters(html_entity_decode($PostInfo[0]), 23);
                        $ThreadPoster = $PostInfo[1];
                        $ThreadAdminLevel = $PostInfo[2];
                        $ThreadTime = $PostInfo[3];

                        echo '
                        <div><a href="'.$serverUrl.'/forum/thread?id='.$gT->LastPostThreadID; if ($gT->LastPostReplyID != 1) { echo '#'.$gT->LastPostReplyID.''; } echo '" style="font-size:13px;">'.$ThreadName.'</a></div>
                        <div style="font-size:13px;padding-top:2px;">by '; if ($ThreadAdminLevel > 0) { echo '<a href="'.$serverUrl.'/profile/'.$ThreadPoster.'/" style="color:#ec2b1d;font-weight:600;">'.LimitTextByCharacters($ThreadPoster, 12).'</a>'; } else { echo '<a href="'.$serverUrl.'/profile/'.$ThreadPoster.'/">'.LimitTextByCharacters($ThreadPoster, 12).'</a>'; } echo ', '.get_short_timeago($ThreadTime).'</div>
                        ';

                    } else {

                        echo 'N/A';

                    }

                echo '
                </div>
            </div>
        </div>
        ';

    }

}

相反,它只是不断抛出“未找到主题”。给我发信息。有什么解决办法吗?

0 个答案:

没有答案