doddsey_65 Posted July 3, 2010 Share Posted July 3, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206650-forum-groups/ Share on other sites More sharing options...
peter_anderson Posted July 3, 2010 Share Posted July 3, 2010 <?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... Quote Link to comment https://forums.phpfreaks.com/topic/206650-forum-groups/#findComment-1080788 Share on other sites More sharing options...
doddsey_65 Posted July 3, 2010 Author Share Posted July 3, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206650-forum-groups/#findComment-1080808 Share on other sites More sharing options...
peter_anderson Posted July 3, 2010 Share Posted July 3, 2010 $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 ) Quote Link to comment https://forums.phpfreaks.com/topic/206650-forum-groups/#findComment-1080810 Share on other sites More sharing options...
doddsey_65 Posted July 3, 2010 Author Share Posted July 3, 2010 it works, sort of, the 1st group is displayed again under the second group. And i know my code is always a mess lol Quote Link to comment https://forums.phpfreaks.com/topic/206650-forum-groups/#findComment-1080812 Share on other sites More sharing options...
doddsey_65 Posted July 3, 2010 Author Share Posted July 3, 2010 any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/206650-forum-groups/#findComment-1080832 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.