Follow us on Twitter!
Hacking isn't just Computers & Exploits. It's a Philosophy. - Mr_Cheese
Thursday, April 24, 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: 26
Guests Online: 24
Members Online: 2

Registered Members: 82903
Newest Member: Piriformis
Latest Articles
View Thread

HellBound Hackers | Computer General | Webmasters Lounge

Author

Question on how to create my SQL table

ranma
Member



Posts: 273
Location: Behind a sphere
Joined: 27.08.05
Rank:
Active User
Posted on 30-07-12 19:46
I am making a website which will categorize articles. The problem is that I want an article to be able to be part of multiple categories.

For example, "tomato" needs to be part of

"foods -> vegetables -> tomato"

and also

"things to throw -> soft -> tomato"

If I had only one category per article, the table design would be easy - a column for categoryID and no problem.

But what about these multiple categories?

I need to be able to list all the articles in a category, so I cannot merely store the categories for an article as an array (unless I use "LIKE" with some delimiters, I guess, but that sounds ugly.)

Ideas? I'm sure someone here has run into this problem before.


Wisdom spared is wisdom squared.
Author

RE: Question on how to create my SQL table

ranma
Member



Posts: 273
Location: Behind a sphere
Joined: 27.08.05
Rank:
Active User
Posted on 30-07-12 20:00
I may have resolved the problem:

I need to create a table that relates article to category and for each association I need a new entry. The primary key for this table will be composite on both the article and category IDs.

Do you think this will work?


Wisdom spared is wisdom squared.
Author

RE: Question on how to create my SQL table

AldarHawk
Member



Posts: 1690
Location: Canada
Joined: 26.01.06
Rank:
Hacker Level 1
Posted on 31-07-12 12:45
You could also store all the areas in the table separated by a delimiter. Then explode the value from the delimiter and you can have multiple categories and keep one cell for this.


Just ask Yahoo!Taboo! http://www.erikwestlake.com
Author

RE: Question on how to create my SQL table

chaos_theory
Member



Posts: 3
Location: United States
Joined: 24.04.11
Rank:
Apprentice
Posted on 01-08-12 02:04
A working, but less elegant method for that would be to make another table for categories entirely, then have each of those categories able to point at the articles you want. You would have to redo your sql search function to look at a different table.


The solution is just where you decided to stop thinking.