This is what my forums currently look like: http://prntscr.com/73oicl
But, as you can see, the categories both say "community", which isn't supposed to happen. The "Test" subcategory should be right under the "Announcements & Updates" subcategory.
I know what the problem is, but I don't know how to fix it.
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");
}
}
As you can see, for each result its going to make a whole new forum div, which means all the Subcategories that are given for that Category aren't going to be together, and each subcategory is going to make a new forum, which I don't want. Is there a way I could like explode the echo to make it so if 2 or more subcategories are in 1 category it won't put out the new div?