这是我的论坛目前的样子: 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?