Re: blog design issue...
| From: | Richard | Date: | Sat, 20 Mar 2010 16:06:32 +0000 |
| Subject: | Re: blog design issue... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-303053@lists.php.net to get a copy of this message | ||
Hi,
> I know you are all probably thinking "What does this have to do with PHP?"
> and in reality... It's probably stretching it a little bit... BUT I am in
> the process of writing a blog software (Yes I'm aware of all the open
> source, and paid stuff out there... I'm doing this to learn :)) I am looking
> at adding "categories" to my blog posts so I can organize my drivel into
> something that looks somewhat professional, or at the very least, organized
> so you can filter out all the crap...
>
> What I'm wondering about though, is would it be better from a database
> design stand point to do a database field for "categories" and then in there
> put "Personal", "Business", "Crap I found funny" Basically 1
> database field
> for all the categories I decide to use. OR should I go the other route and
> do 1 database field for each category?
>
> This is going to be a small blog to start, but I guess I should always be
> looking at performance, security, & maintainability right?
>
> I did read the post that tedd put up about looking at storing variables
> differently and am considering going that route... But just wanted to know
> what you all think :)
>
> Oh.... I'm also not expecting to have more then 4 or 5 categories at the
> most.... Unless I release the blog to the public and take wordpress down :P
You could use a SET field type. Internally MySQL uses numbers (a bit
mask IIRC) for them. Though you will be limited to 32 categories.
Eg:
Categories table:
ID Name
============
1 Personal
2 Business
4 Crap I found funny
Articles table:
ID Title Category
=======================
1 My first blog entry 1
2 A joke from work 6
3 A joke from home 5
4 A joke 4
The numbers are bitwise sums of the corresponding category IDs.
eg.4&2=6. I think. MySQL has some built in functions for dealing with
sets, like FIND_IN_SET() IIRC, which make life a lot easier.
--
Richard Heyes
HTML5 canvas graphing: RGraph - http://www.rgraph.net (updated
13th March)
Lots of PHP and Javascript code - http://www.phpguru.org