4

これは私のフォーラムの現在の様子です: http://prntscr.com/73oicl

しかし、ご覧のとおり、両方のカテゴリに「コミュニティ」と書かれていますが、これは想定外のことです。「テスト」サブカテゴリは、「お知らせと更新」サブカテゴリのすぐ下にある必要があります。

問題が何であるかはわかっていますが、それを修正する方法がわかりません。

    function getForums($id) {
    $currentHost = "http://$_SERVER[HTTP_HOST]";
    $query = "SELECT * FROM forums, categories";
    try {
        global $db;
        $stmt = $db->prepare($query); 
        $stmt->execute();
        $result = $stmt->fetchAll();
        foreach($result as $row) {
            $category_title = $row['category_title'];
            $forum_id = $row['forum_id'];
            $forum_title = $row['forum_title'];
            $forum_topic_count = $row['forum_topic_count'];
            $forum_post_count = $row['forum_post_count'];
            $forum_last_topic_id = $row['forum_last_topic_id'];
            $forum_last_topic = $row['forum_last_topic'];
            $forum_last_date = $row['forum_last_date'];
            $forum_last_user = $row['forum_last_user'];
            $fixed_last_topic = substr($forum_last_topic,0,25).'...';
            echo '<div class="forum pleft">
                    <div class="forum-header">
                        <span class="header-text">'.$category_title.'</span>
                    </div>
                    <table>
                        <tr>
                            <td class="title"><a href="'.$currentHost.'/forums/view-forum/index.php?cid='.$category_id.'&fid='.$forum_id.'">'.$forum_title.'</a></td>
                            <td class="topics">'.$forum_topic_count.'</td>
                            <td class="posts">'.$forum_post_count.'</td>
                            <td class="lastpost"><a href="'.$currentHost.'/forums/view-thread/index.php?cid='.$id.'&fid='.$forum_id.'&tid='.forum_last_topic_id.'">'.$fixed_last_topic.'</a> by <a href="'.$currentHost.'/users/index.php?username='.$forum_last_user.'">'.$forum_last_user.'</a> at '.$forum_last_date.'</td>
                        </tr>
                    </table>
                </div>';
        }
    }
    catch(PDOException $ex) {
        die("error");
    }
}

ご覧のとおり、結果ごとにまったく新しいフォーラム div が作成されます。これは、そのカテゴリに指定されたすべてのサブカテゴリが一緒になるわけではなく、各サブカテゴリが新しいフォーラムを作成することを意味します。したくない。エコーを爆発させて、2 つ以上のサブカテゴリが 1 つのカテゴリにある場合、新しい div を出力しないようにする方法はありますか?

4

1 に答える 1