Love2c0de Posted May 28, 2013 Share Posted May 28, 2013 (edited) Good afternoon, I am attempting to create a custom forum for my own personal website which I'm working on but I can't really grasp the concept of how my database should be set up. At the moment I have a 'forum_categories' table with 5 fields; id, forum, topics, posts, last_post. I have put some dummy data into my table so that I can test displaying it. I have attached 2 screenshots, first one is my database structure and the second one is the data. The idea is that when they first visit the forum page, the topics and posts table columns should count the amount of topics and posts for each section and of course, last_post is self explanatory. At this present time I'm not sure on what to do. I know I will need more tables holding the actual posts but I'm not sure how to properly link each topic to the correct section and how to link the topics with the posts. Do I need 2 more tables, one say topics and one say posts and link them with ID's? Is there a standard way to create forums or could anyone point me in the direction of credible tutorials? I look forward to your help. Kind regards, L2c. Edited May 28, 2013 by Love2c0de Quote Link to comment https://forums.phpfreaks.com/topic/278482-creating-a-basic-forum/ Share on other sites More sharing options...
ignace Posted May 28, 2013 Share Posted May 28, 2013 (edited) There is nothing complex about a forum. At the bare basic you have a Topic and a Post. Everything else are just categories, which in turn can have categories. Instead of starting out with a database schema, try it out in code and populate simple array's, something like this: namespace Forum; class Topic implements Countable, IteratorAggregate { private $posts = array(); public function __construct(Post $firstPost) { $this->addPost($firstPost); } public function addPost(Post $post) { $this->posts[] = $post; } public function receivedReplies() { return ($this->count() - 1) > 1; } public function count() { return count($this->posts); } public function getIterator() { return new ArrayIterator($this->posts); } public function lastReceivedReplyAt() { if (!$this->receivedReplies()) { return null; } $date = end($this->posts)->getPostDate(); reset($this->posts); return $date; } } class Post { private /** @var User */ $author; private /** @var string */ $subject; private /** @var string */ $text; private /** @var \DateTime */ $postDate; private /** @var \DateTime */ $modifyDate; public function __construct($author, $subject, $text, $postDate = null) { $this->author = $author; $this->subject = $subject; $this->text = $text; $this->postDate = $postDate ?: new DateTime; } } class User { private $alias; } Edited May 28, 2013 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/278482-creating-a-basic-forum/#findComment-1432775 Share on other sites More sharing options...
Love2c0de Posted May 28, 2013 Author Share Posted May 28, 2013 Good evening ignace, Could you elaborate a little more on what are my possible options. Do I really need my 'forum_categories' table then? Thank you for your response. Kind regards, L2c. Quote Link to comment https://forums.phpfreaks.com/topic/278482-creating-a-basic-forum/#findComment-1432778 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.