0

I have built a blog site where the authors name is also a link to their Bio. Previously each Blog entry had a "author_link" in a separate column in the blog_table which worked. However is this an efficient way to do this or should the links be in their own associated table, or should it be done some other way that I am not familiar with?

The only dynamic language I have any familiarity with is PHP so any answer that takes a knowledge of anything else is probably beyond my ability to implement for now unless of course it is fairly simple.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
  • 1
    If you want to keep it simple, then keep going the way you're doing it now. Otherwise, you will end up having to do JOINS later on. *I for one*, have yet to conquer those. – Funk Forty Niner Mar 17 '14 at 17:56
  • 2
    If any author can only have one link, then I would think having this link as a field in the author table would be best, since this is a property of the author. If authors can have multiple URL's, then you would need to relate the authors to the URL's which reside in separate table. – Mike Brant Mar 17 '14 at 17:57
  • I agree with Mike Brant's comment. Put it in the author's table, so any time the author updates their bio link, all dynamic blog entry pages will automatically be updated with the new link. – Marcus Adams Mar 17 '14 at 18:25

1 Answers1

0

Use a separate table and a join.

What you're asking about is called normalisation. There's a question that covers it quite well here: What is Normalisation (or Normalization)?.

Essentially it is having one source of each piece of data, held in a query-able manner. (At least this how I find it easiest to think about.)

Sometimes it is worth de-normalising tables (ie, when the join(s) is/are too expensive) but these occasions are not regular occurrences and you should normalise by default.

Joins are not too difficult. A join in this case would look something (roughly) like this:

SELECT a.author_link
FROM blog_table b
LEFT JOIN author_table a
ON b.author_id = a.author_id
WHERE ...

(assuming author_id columns in both)

Your choice of language doesn't really matter; most popular languages have connectors of mysql. As you will probably use PHP, use the mysqli or PDO libraries (not the old, deprecated mysql library).

Community
  • 1
  • 1
jam3
  • 129
  • 5