Jump to content

Forum groups


doddsey_65

Recommended Posts

my mind has drawn a blank so i need help.

 

look here http://thevault.cz.cc/forum/index.php for a better look.

 

Im making a forum and i have 4 database tables: groups, forums, threads, and posts

 

all i want to do is show the forums on the home page categorized by which group they are in like normal forums do.

 

ie the forums belonging to group NEWS will display together with the news header at the top of the table

 

and then the different groups under that with their own table headers.

 

Sounded simple enough to me but i cant do it. When i try it just displays a header above each forum rather than a header at the top of the forums in a group. Hope this makes sense.

Link to comment
Share on other sites

<?php
$q = "SELECT * FROM `groups`";
$result = $sql->query($q);
while($row = $result->fetch_assoc()){
        // display header information
        $id = $row['id'];
        $q2 = "SELECT * FROM `forums` WHERE group = '$id'";
        $result2 = $sql->query($q2);
        while($row2 = $result2->fetch_assoc()){
                //display forum information
//etc...

Link to comment
Share on other sites

thanks, i tried yours but i couldnt get it to work. heres what i have now:

 

$sql = mysql_query("SELECT * FROM forum_groups") or die (mysql_error());
while ($row = mysql_fetch_object($sql)) {

$groupid = $row->groupid;
$forumid2 = $row->forumid;
$groupname = $row->groupname;
}


echo '
<td class="forum-left">'.$groupname.'</td>
<td class="forum-middle">Topics</td>
<td class="forum-middle">Posts</td>
<td class="forum-right">Last Post</td></tr>';


$sql = mysql_query("SELECT * FROM $forums WHERE groupid = $groupid") or die (mysql_error());
while ($row = mysql_fetch_object($sql)) {

echo '<tr><td class="forum2">
<a href="index.php?f='.$row->id.'">' . $row->name . '</a><br />
<h4 style="font-size:10px;">'.$row->description.'</h4>
</td><td class="forum">';

$id = $row->id;

$sql2 = mysql_query("SELECT * FROM $threads WHERE forumid = '$id'") or die (mysql_error());
$num = mysql_num_rows($sql2);
echo $num . '</td><td class="forum">';


$sql3 = mysql_query("SELECT * FROM forum_posts WHERE forumid = '$id'") or die (mysql_error());
$num2 = mysql_num_rows($sql3);
echo $num2 . '</td><td class="forum">';


echo 'By '.$row->lastpost.' <h5 style="font-size: 10px;">On ';

echo date("F j, Y, g:i a", strtotime($row->date));

echo '</h5></td></tr><tr>';

}

 

there are currently 2 items in group 1 and 1 in group 2. This displays the stuff in group 1 properly but doesnt display stuff from group 2 under it as i had hoped.

Link to comment
Share on other sites

$sql = mysql_query("SELECT * FROM forum_groups") or die (mysql_error());
while ($row = mysql_fetch_object($sql)) {
$groupid = $row->groupid;
$forumid2 = $row->forumid;
$groupname = $row->groupname;
echo '
<td class="forum-left">'.$groupname.'</td>
<td class="forum-middle">Topics</td>
<td class="forum-middle">Posts</td>
<td class="forum-right">Last Post</td></tr>';
$sql2 = mysql_query("SELECT * FROM forums WHERE groupid = $groupid") or die (mysql_error());
while ($row2 = mysql_fetch_object($sql2)) {
	echo '<tr><td class="forum2">
<a href="index.php?f='.$row2->id.'">' . $row2->name . '</a><br />
<h4 style="font-size:10px;">'.$row2->description.'</h4>
</td><td class="forum">';
	$id = $row2->id;
	$sql3 = mysql_query("SELECT * FROM threads WHERE forumid = '$id'") or die (mysql_error());
	$num = mysql_num_rows($sql3);
	echo $num . '</td><td class="forum">';
	$sql4 = mysql_query("SELECT * FROM forum_posts WHERE forumid = '$id'") or die (mysql_error());
	$num2 = mysql_num_rows($sql4);
	echo $num2 . '</td><td class="forum">';
	echo 'By '.$row2->lastpost.' <h5 style="font-size: 10px;">On ';
	echo date("F j, Y, g:i a", strtotime($row->date));
	echo '</h5></td></tr><tr>';
}
}

 

Try this (I cleaned up some of the code, to the way I can read it better ;))

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.