Jump to content

Recommended Posts

I am stuck on building the Category part for my forum :S i got almost everything else done but i been stuck on this part for a while now i keep looking at it and then going to the rest of the script and working on them but i thought i would come to the forums for help on this  ??? its drivin me nuts lol..

 

I want it to be like a regular forum somewhat.. like Category name like General then there will be like 4 or 5 different threads.. and so forth

 

see i got it to read threads just fine but im not sure on how to do group by categories

 

can someone help me please..

 

here is my Category Page..

 

<table width="100%" height="20" border="0"  bgcolor="#CFC095" class="Header_box"  cellpadding="2" cellspacing="0">
  <tr>
    <th bgcolor="#514833" class="background_head" width="80%">Forum</th>
    <th bgcolor="#514833" class="background_head" width="10%">Topics</th>
    <th bgcolor="#514833" class="background_head" width="10%">Post</th>
  </tr>
</table>
<table width="100%" height="20" border="0"  bgcolor="#CFC095" class="Header_box"  cellpadding="2" cellspacing="0">
  <tr>
    <th bgcolor="#514833" class="background_head" width="60%" align="left">CATEGORY</th>
  </tr>
</table>
<table width="100%"  border="1" bordercolor="CFC095" cellpadding="3" cellspacing="0" bgcolor="#CFC095" class="Box_border">
<?php 

$id = $_GET['id'];

$get_topic = mysql_query("SELECT id, heading, description FROM header ORDER BY id DESC") or die(mysql_error());	
	while($topic_info = mysql_fetch_array($get_topic)) {
		$id = $topic_info['id'];
		$heading = stripslashes($topic_info['heading']);
		$description = $topic_info['description'];

$get_num_topics = mysql_query("SELECT forumid FROM forum_question WHERE forumid = $id");
    $topics = mysql_num_rows($get_num_topics);

$get_num_posts = mysql_query("SELECT forumid FROM forum_answer WHERE forumid = $id");
$posts = mysql_num_rows($get_num_posts);
?>
  <tr>
    <td bgcolor="#4D4531" class="background" width="80%" align="left"><a href="../index.php?pages=topic&id=<?php echo $id; ?>"><?php echo $heading; ?></a><br /><?php echo $description; ?></td>
    <td bgcolor="#4D4531" class="background" width="10%"><?php echo $topics; ?></td>
    <td bgcolor="#4D4531" class="background" width="10%"><?php echo $posts; ?></td>
<?php

if($_SESSION['user_level'] == 5) {


?>
  <tr>
    <td bgcolor="#4D4531" class="background" align="right" width="60%"> </td>
    <td bgcolor="#4D4531" class="background" align="right" width="10%"><a class="two" href="../index.php?pages=topic_edit2&id=<?php echo $id; ?>">Edit</a> | <a class="two" href="../index.php?pages=forum_functions&action=delete1&id=<?php echo $id; ?>">Delete</a></td>
<td bgcolor="#4D4531" class="background" width="10%"><a href="../index.php?pages=add_heading"><strong>Create New Subject</strong></a></td>
  </tr>
  <?php
  }
  }
  ?>
  </table>

 

Thank you

Smackie

Link to comment
https://forums.phpfreaks.com/topic/64103-forum-category-help/
Share on other sites

Ok i tried grouping them not sure if i did it right but it don't got any errors which is kinda good but when you look at the forum the categories are coming out right Test1 and Test2 but the thing is Test1 should only have 1 thread in it and Test2 should have 3 but if you look at it there is 4 in both which isnt good

 

here is the code i got now

 

<table width="100%" height="20" border="0"  bgcolor="#CFC095" class="Header_box"  cellpadding="2" cellspacing="0">
  <tr>
    <th bgcolor="#514833" class="background_head" width="80%">Forum</th>
    <th bgcolor="#514833" class="background_head" width="10%">Topics</th>
    <th bgcolor="#514833" class="background_head" width="10%">Post</th>
  </tr>
</table>
<?php
$get_category = mysql_query("SELECT * FROM category GROUP BY id") or die(mysql_error());	
	while($row = mysql_fetch_array($get_category)) {
	?>
<table width="100%" height="20" border="0"  bgcolor="#CFC095" class="Header_box"  cellpadding="2" cellspacing="0">
  <tr>
    <th bgcolor="#514833" class="background_head" width="60%" align="left"><B><U><font size="2"><?php echo $row['category']; ?></font></u></b></th>
  </tr>
</table>
<table width="100%"  border="1" bordercolor="CFC095" cellpadding="3" cellspacing="0" bgcolor="#CFC095" class="Box_border">
<?php 
    
$id = $_GET['id'];	
    
$get_topic = mysql_query("SELECT * FROM header ORDER BY catid") or die(mysql_error());	
	while($topic_info = mysql_fetch_array($get_topic)) {
		$id = $topic_info['id'];
		$heading = stripslashes($topic_info['heading']);
		$description = $topic_info['description'];

$get_num_topics = mysql_query("SELECT forumid FROM forum_question WHERE forumid = $id");
    $topics = mysql_num_rows($get_num_topics);

$get_num_posts = mysql_query("SELECT forumid FROM forum_answer WHERE forumid = $id");
$posts = mysql_num_rows($get_num_posts);
?>
  <tr>
    <td bgcolor="#4D4531" class="background" width="80%" align="left"><a href="../index.php?pages=topic&id=<?php echo $id; ?>"><?php echo $heading; ?></a><br /><?php echo $description; ?></td>
    <td bgcolor="#4D4531" class="background" width="10%"><?php echo $topics; ?></td>
    <td bgcolor="#4D4531" class="background" width="10%"><?php echo $posts; ?></td>
<?php

if($_SESSION['user_level'] == 5) {


?>
  <tr>
    <td bgcolor="#4D4531" class="background" align="right" colspan="3"><a class="two" href="../index.php?pages=topic_edit2&id=<?php echo $id; ?>">Edit</a> | <a class="two" href="../index.php?pages=forum_functions&action=delete1&id=<?php echo $id; ?>">Delete</a></td>
  </tr>
    <tr>
    <td bgcolor="#4D4531" class="background" align="right" colspan="3"><a href="../index.php?pages=add_heading"><strong>Create New Subject</strong></a></td>
  </tr>
  <?php
  }
  }
  }
  ?>
  </table>

Link to comment
https://forums.phpfreaks.com/topic/64103-forum-category-help/#findComment-320491
Share on other sites

I'm confused. I'm not sure I can figure that out without knowing what fields your table has. It seems like you may be comparing an "id" with a "catid." If you could explain your tables a little more, it would help.

 

By the way, why do you need a number for category, anyway? If you just use the category name you wouldn't even need the extra category table. Just a suggestion, maybe you use the number somewhere else.

Link to comment
https://forums.phpfreaks.com/topic/64103-forum-category-help/#findComment-320515
Share on other sites

in database i have

 

category

-------------

id, category

 

header

-------------

id, catid, heading, description

 

 

i don't see why it would matter if i had it as id instead of names anyways..

 

go to http://kwallen-islands.uni.cc/index.php?pages=forum and you can see what the forum looks like

Link to comment
https://forums.phpfreaks.com/topic/64103-forum-category-help/#findComment-320541
Share on other sites

For every 'id' in table 'category' you are retrieving every 'id' in 'header'. From there you get the forum by that 'id', but there is no criteria for that 'id'. I would expect that the output is printing the category correctly, but each category shows EVERY forum that you have. I actually think that all you need to do is change this:

$get_topic = mysql_query("SELECT * FROM header ORDER BY catid") or die(mysql_error());	

 

to:

$get_topic = mysql_query("SELECT * FROM header GROUP BY catid") or die(mysql_error());	

 

 

The reason I suggested not to have the id is because it just makes another table to query from. It was just an idea that might help you keep it simpler. To go along with that, I think you should try to change the way you do this query. You could get the whole thing done in one query and one loop. Instead of making a new query for every category, If you already have everything queried, you can just check if the last category was the same as the next one. That is how I do it.

Link to comment
https://forums.phpfreaks.com/topic/64103-forum-category-help/#findComment-320589
Share on other sites

If i change it to

 

$get_topic = mysql_query("SELECT * FROM header GROUP BY catid") or die(mysql_error());	

 

i get only 2 threads in each and if im getting what your saying is have a table called category in header and have 1 loop that would give me a category name above every single thread i dont want that.. and also I'm not a big fan of people telling me i need to do something the way they do it.. i like to do it my way it helps me with keeping things easy for me..

Link to comment
https://forums.phpfreaks.com/topic/64103-forum-category-help/#findComment-320601
Share on other sites

That's fine, do it however you want. I was just making a suggestion.

 

My last suggestion about changing it to GROUP was pretty stupid, looking back on it, now. Try changing it to this:

"SELECT * FROM header WHERE catid=" . $row['id'] . " ORDER BY catid"

 

Of course, I'm not entirely sure that is how your table works because I can't see it, but the idea is that you need to compare the 'catid' you are retrieving to the current category that was just printed above. In the statement I suggest above, I am assuming that the 'id' field in the 'category' table is directly related to the 'catid' field in the 'header' table. If it isn't, find a way to compare the current category of the outer-loop to the 'catid'.

Link to comment
https://forums.phpfreaks.com/topic/64103-forum-category-help/#findComment-320616
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.