Jump to content

[SOLVED] Advise on own forum.


Anzeo

Recommended Posts

Hi everyone,

 

 

 

I'm currently working on my own (simple) forum and I've got a little question:

 

Ive made 4 tables: CATEGORY, FORUM (which has an attribute Category), TOPIC (which has an attribut Forum) and POST.

 

My question is, what should I do best: consider a topic as a post and thus add the author, date, message, ... to my TOPIC table or should it just be the title and id and should I put the first topic post in my POST table?

 

 

 

Any help greatly appreciated,

Anzeo

Link to comment
Share on other sites

If you are creating a forum then you will want to look into database normalization.

 

What I'd do is create two tables

 

topics and posts

 

Self explanatory the table names. topics stores topics and posts stores posts.

 

The first post of the topic will be stored in the topics forum. Then any posts made in that topic will be stored in the posts table. You link the two tables together by storing the topics id in the posts table. Then when you go to display the posts for the specific topic you do a simple query like this:

 

SELECT * FROM posts WHERE topic_id = $topic_id

 

That is obviously very basic. Your query will come more advanced than that if you go into database normalization.

Link to comment
Share on other sites

Well, I got another question and I thought it'd be better to continue one topic rather then a new for every question concerning the same subject so here goes.

 

I got a problem while receiving my forum list, this is the code I use:

 

<table width="700" border="0" cellspacing="0" cellpadding="0">
<?php
while($catqry = mysql_fetch_array(mysql_query("SELECT * FROM CATEGORIE ORDER BY VolgNr")))
{
	$CatNaam = $catqry["Naam"];
	$CatId = $catqry["ID"];
?>
<tr><td><a href="view.php?cat=<?php echo "$CatId";?>"><?php echo "$CatNaam"; ?></a></td></tr>
<?php
	$frmrowsqry = mysql_fetch_array(mysql_query("SELECT COUNT(*) AS Limit FROM FORUM WHERE Categorie='$CatId'"));
	$Limit = $frmrowsqry["Limit"];
	while($frmqry = mysql_fetch_array(mysql_query("SELECT * FROM FORUM WHERE Categorie = '$CatId' ORDER BY VolgNr LIMIT='$Limit'")))
	{
		$FrmNaam = $frmqry["Naam"];
		$FrmId = $frmqry["ID"];
		$FrmBeschrijving = $frmqry["Beschrijving"];
?>
<tr><td><a href="vieuw.php?frm=<?php echo "$FrmId";?>"><?php echo "$FrmNaam";?></a></td></tr>
<?php
	}
}
?>
</table>

 

And this is the output

 

Any idea what's causing this problem?

Link to comment
Share on other sites

which lines are 11 and 13?

 

actually is is

\$frmrowsqry = mysql_fetch_array(mysql_query("SELECT COUNT(*) AS Limit FROM FORUM WHERE Categorie='$CatId'"));

and

while($frmqry = mysql_fetch_array(mysql_query("SELECT * FROM FORUM WHERE Categorie = '$CatId' ORDER BY VolgNr LIMIT='$Limit'")))

?

 

I'm not sure that mysql_fetch array works like that.. not sure though.

I think you need to query the table and save it as an array, then fetch the array

Link to comment
Share on other sites

Do you get the error about line 11 and 13? Because i don't, I get my category listed once and then it's forum is fetched unlimited so I receive output like this:

 

News

General

General

General

General

...

..

.

 

So I wander why it's being fetched continously. Besides that, I've used mysql_fecth_array like that before and it never gave me problems so I don't think that's causing the problem.

Link to comment
Share on other sites

If you are creating a forum then you will want to look into database normalization.

 

What I'd do is create two tables

 

topics and posts

 

Self explanatory the table names. topics stores topics and posts stores posts.

 

The first post of the topic will be stored in the topics forum. Then any posts made in that topic will be stored in the posts table. You link the two tables together by storing the topics id in the posts table. Then when you go to display the posts for the specific topic you do a simple query like this:

 

I'd be inclined to disagree, it'd certainly mean that you'd be needlessly using more extensive queries to select all of the posts from a topic, as you'd need to select the post field from the topic and all the other posts themselves.

 

It's also the case, that you'd need to complicate things further when editing a post, you'd need a conditonal statement to check if it's the first post or not, so that it's updating data in the right table. Whilst this is of course pretty simple to do, it still complicates things needlessly, might aswell normalise everything fully if you're going to at all.

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.