Anzeo Posted April 10, 2007 Share Posted April 10, 2007 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 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 10, 2007 Share Posted April 10, 2007 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. Quote Link to comment Share on other sites More sharing options...
Anzeo Posted April 10, 2007 Author Share Posted April 10, 2007 Thanks alot, exactly the answer I needed Topic solved^^ Quote Link to comment Share on other sites More sharing options...
Anzeo Posted April 10, 2007 Author Share Posted April 10, 2007 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? Quote Link to comment Share on other sites More sharing options...
Dragen Posted April 10, 2007 Share Posted April 10, 2007 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 Quote Link to comment Share on other sites More sharing options...
Anzeo Posted April 10, 2007 Author Share Posted April 10, 2007 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. Quote Link to comment Share on other sites More sharing options...
Anzeo Posted April 10, 2007 Author Share Posted April 10, 2007 Anyone? I'm sorry if I sound a bit hasted, but I'm eager to continue my work TIA Quote Link to comment Share on other sites More sharing options...
Anzeo Posted April 10, 2007 Author Share Posted April 10, 2007 Does anyone know why my code gives a problem? I posted it a few posts up, any help greatly appreciated as I cannot figure out what is causing this and why. TIA Quote Link to comment Share on other sites More sharing options...
Hell Toupee Posted April 10, 2007 Share Posted April 10, 2007 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. Quote Link to comment Share on other sites More sharing options...
Anzeo Posted April 10, 2007 Author Share Posted April 10, 2007 Hmm I think both ways would work, either way you'd need big querries , but does anyone want to take a look at the code and tell me what's wrong with it? Quote Link to comment 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.