I want to make a database where people login and insert jokes.
//Design 1
joke
joke_id
joke
category_id
author_id
category
category_id
category
author
author_id
author_name
// Design 2 - this is given in a php book
joke
joke_id
joke
author_id
category
category_id
category
author
author_id
author_name
jokecategory
joke_id
category_id
Thanks
Better design?
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Better design?
The difference between the two is that in the first one each joke can be in only one category, in the second a joke can be in multiple categories. Which one do you want?
(#10850)
Re: Better design?
Thanks.
I was confused looking at the 2nd design. One more thing, so when the user adds in the 2nd design a seperate insert/update statement has to be written for inserting categories (i guess it should be checkboxes for multiple selection)?
I was confused looking at the 2nd design. One more thing, so when the user adds in the 2nd design a seperate insert/update statement has to be written for inserting categories (i guess it should be checkboxes for multiple selection)?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Better design?
Yes, you would need to insert/update a record for each joke_category relationship. So:
joke (id, text)
1, Two peanuts were walking down the road, and one was assaulted peanut
category (id, name)
10, Jokes about peanuts
11, Jokes that kill
joke_category (id, jokeid, categoryid)
1, 1, 10
2, 1, 11
joke (id, text)
1, Two peanuts were walking down the road, and one was assaulted peanut
category (id, name)
10, Jokes about peanuts
11, Jokes that kill
joke_category (id, jokeid, categoryid)
1, 1, 10
2, 1, 11
(#10850)