Follow us on Twitter!
Understanding is the answer, hatred is the problem, and hackers are the slaves abused and destroyed in the process of peace online - Deshouleres
Friday, April 18, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 17
Guests Online: 16
Members Online: 1

Registered Members: 82822
Newest Member: TheBunter
Latest Articles
View Thread

HellBound Hackers | Computer General | Hacking in general

Author

Structure of Category table in Blog db

goluhaque
Member



Posts: 197
Location: India
Joined: 17.02.10
Rank:
Apprentice
Warn Level: 30
Posted on 16-03-11 16:45
So, I was building a blog, and wanted to assign categories to blog posts. What should be the structure of the post table? Should there be fields for each category(or its id) with boolean datatype? Or should all the category ids be limited to a single field?


That applause I receive from y'all on posting this post would have gotten me drunk on power if I hadn't already been high on life.
Author

RE: Structure of Category table in Blog db

starofale
Member



Posts: 218
Location: England
Joined: 05.12.07
Rank:
Moderate
Posted on 16-03-11 23:22
I wouldn't limit a post to a single category. Maybe have a look at some open source blogging platforms and see what they do?


Try a new search engine
Author

RE: Structure of Category table in Blog db

stealth-
Member



Posts: 1003
Location: Eh?
Joined: 10.04.09
Rank:
Mad User
Posted on 17-03-11 03:54
Just going with one field would make far more sense, to me at least. Having multiple boolean fields could make the db larger, more cluttered to look at, and more complicated when it came to wanting to add more categories. One field offers much better scalability/simplicity. Either way, for a small blog it won't matter too much.

Disclaimer: I'm hardly a MySQL expert.


The irony of man's condition is that the deepest need is to be free of the anxiety of death and annihilation; but it is life itself which awakens it, and so we must shrink from being fully alive.
http://www.stealt. . .
http://www.stealth-x.com
Author

RE: Structure of Category table in Blog db

goluhaque
Member



Posts: 197
Location: India
Joined: 17.02.10
Rank:
Apprentice
Warn Level: 30
Posted on 17-03-11 16:53
starofale wrote:
I wouldn't limit a post to a single category. Maybe have a look at some open source blogging platforms and see what they do?

In Joomla, a single post can only be assigned a single category, and I couldn't seem to make out the heads or tails in Wordpress.


That applause I receive from y'all on posting this post would have gotten me drunk on power if I hadn't already been high on life.
Author

RE: Structure of Category table in Blog db

ynori7
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 17-03-11 17:36
You could just make your category field fairly large and allow multiple categories in the same field separated by a delimiter. So it could look like "|category1|category2|category3|" and you could just search WHERE category LIKE "%|categoryName|%".


halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg
ynori7 http://halls-of-valhalla.org
Author

RE: Structure of Category table in Blog db

j4m32
Member

Your avatar

Posts: 81
Location:
Joined: 01.05.10
Rank:
Newbie
Posted on 17-03-11 18:33
This is very similar to what ynori suggested but I would use an extra table...

Make a table for all the categories, and make them all able to have a parent category id if you want sub-sectioned categories:

tbl_categories
cid, parentid, name(, metadata - depends if you want to embed meta ddata for search engines)

Make cid a key & auto_increment.

Easier to maintain a table that you can modify the categories and tags in metadata since blogs are fueled by: search engine hits & peer suggestion(link sharing etc).

Code

INSERT INTO `tbl_categories`(parentid, name, metadata) VALUES(1,'Hax0ring','hacking, hacks, moar catch phrases here')





Then for multiple categories, similar to what ynori said, use a a delimiter but you then need only reference the categories primary ids (cid) to

tbl_posts
id, title, catids, content, blah, blah.

Code

INSERT INTO `tbl_posts`(title catids, content, blah, blah) VALUES ('Welcome to the blog', '1,5,6,9','My really interesting super article',stuff, stuff....)





Either as ynori said, use pipe characters as a delimiter, csv (comma separated values) as in my example.
Once you've exploded the string/separated each item from the list, it's not too hard to do an SQL join statement or a quick second query for the relevant information.

Alternatively:

If you don't fany that, and you know that the categories will remain rather static, there is nothing "wrong" in using a simple array. Create a file in a convenient directory containing the array, that you can include where necessary, I guess.

Most would argue this is less flexible, it's a bit harder to process the text to change a particular field - compared to a database.

Jim,
Author

RE: Structure of Category table in Blog db

goluhaque
Member



Posts: 197
Location: India
Joined: 17.02.10
Rank:
Apprentice
Warn Level: 30
Posted on 21-03-11 15:37
Got a better solution.Say, I make a new table wherein there is a cat_id and the name of the category it represents. There won't be a new field in the Post table, but I will create a new table X where

Code
Cat_Id              Post

01                      04
01                      05
02                      04[





That applause I receive from y'all on posting this post would have gotten me drunk on power if I hadn't already been high on life.