Page 1 of 1

How do i implement Coments that span multiple tables

Posted: Sat Nov 10, 2007 8:16 am
by iceangel89
ok i think this is common, you want to have a regular blog entry, portfolio, etc to have comments

so what i can do is have these tables

BLOG
PORTFOLIO
BLOG_COMMENTS
PORTFOLIO_COMMENTS

but since both comments table will have the same columns, can i merge them? so that they can reference from 2 tables? is it possible?

Posted: Sat Nov 10, 2007 8:19 am
by feyd
Yes, it's possible.

Posted: Sat Nov 10, 2007 6:00 pm
by califdon
Without knowing what is in those tables, it's impossible to answer your question.

Posted: Sat Nov 10, 2007 8:54 pm
by iceangel89
feyd wrote:Yes, it's possible.
how do i do it?
califdon wrote:Without knowing what is in those tables, it's impossible to answer your question.
BLOG will have things like: BlogID, Title, Content, DateTime, UserID - it can have more but for now
PORTFOLIO shld have: PortfolioID, Title, Content, ImageURL,
COMMENTS table will have CommentID, UserID, Content, and either BlogID or CommentID

actually, what do [s]u[/s] you guys have in [s]ur[/s] your tables and do [s]u[/s] you do from scratch? or use a CMS/Blogger? i was thinking doing from scratch allows me more practice?
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.

Posted: Mon Nov 12, 2007 3:14 pm
by califdon
If you are referring to this forum (which is not a blog or CMS and requires very different logic than those applications), it is just a standard phpBB forum, customized with our logo. It probably required more than a man-year to write, by very experienced programmers. I commend you on your eagerness to learn, and writing software from scratch is an excellent way to learn, but you need to start with a much simpler project. When you ask a simple question about a complex topic, you're likely to get answers that won't fit your needs. Your original question was:
since both comments table will have the same columns, can i merge them? so that they can reference from 2 tables? is it possible?
The answer to that question would depend on a whole lot of other factors. The short answer is Yes, anything is possible. That's what feyd meant in his response. The long answer involves everything else in your database, as to whether merging tables makes sense. In relational database theory, a table represents an entity in the part of the real world that your database is modeling, so unless I know exactly what you are trying to model, I can't give you any useful answer as to how to structure your tables. It would take a lot of discussion and analysis. In some cases, all the Comments should be in the same table, in other cases, they should not. It all depends on the rest of your data and their relationships.

If you find this discussion too complex or too boring, it's because this is the business of database design. There are no shortcuts. It's complex and sometimes boring.