Jump to content

Building PHP forum system and need some help


Recommended Posts

Ok i am building a custom PHP forum system for my site and i am pretty much done, but having troubles with one thing linking categories with boards (aka forums in database).


I will start by covering my database layout


Categorycat_id | int(8) | primary | auto incrcat_name | var(255)|2|Test 2|3|Test 3|1|Test 1Forumid | int(8) | primary | auto_incrforum_cat | int(8) <-- forum cat "category" is just ID of category it belongs toname | var(255)desc | var(255)

position | smallint(6)|1|1|Test| Just a simple forum test|2|3|More Test | Just a 2nd test forum|3|1|Bugs| Bugs and related go here


and this is my php for displaying the boards, like i said not sure how to go about adding categories.

<?php$dn2 = mysqli_query($conn,'select id, name from forum_cats where id order by id asc');while($dnn2 = mysqli_fetch_array($dn2)){?><div class="panel-heading"><table class="cat-table">  <tr>    <td width="81%"><h3 class="panel-title"><span class="glyphicon glyphicon-home"></span><?php echo $dnn2['name']; ?></h3></td>    <td width="12%"><h3 class="panel-title">Topics</h3></td>    <td width="7%"><h3 class="panel-title">Replies</h3></td>  </tr></table></div><div class="panel-body"><table class="cat-table"><?php$dn1 = mysqli_query($conn,'select b.id, b.name, b.description, b.position, (select count(t.id) from topics as t where t.parent=c.id and t.id2=1) as topics, (select count(t2.id) from topics as t2 where t2.parent=c.id and t2.id2!=1) as replies from boards as b group by b.id order by b.position asc');$nb_cats = mysqli_num_rows($dn1);while($dnn1 = mysqli_fetch_array($dn1)){?><tr class="cat-col">    <td class="cat-row" width="84%"><a href="topics.php?id=<?php echo $dnn1['id']; ?>" class="title"><?php echo htmlentities($dnn1['name'], ENT_QUOTES, 'UTF-8'); ?></a>        <div class="description"><?php echo $dnn1['description']; ?></div></td>    <td class="cat-row" width="12%"><?php echo $dnn1['topics']; ?></td>    <td class="cat-row" width="7%"><?php echo $dnn1['replies']; ?></td>    </tr><?php}?>    </table></div><?php}?> 

Image attached is what i am aim for... So as of right now categories are displaying right but all boards show up under all categories...demo in reply


Edited by josiec09
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...