Jump to content

Recommended Posts

I have a table which needs to store "points" for 8 groups. It gets a new entry weekly, but the points are updated many times daily. There may be more groups added in the future, but I would know about it first, and have the change to add a new column to the table. This is how it currently looks:

CREATE TABLE `weeklyPoints` (
  `weekID` int(10) unsigned NOT NULL auto_increment,
  `start` int(11) NOT NULL default '0',
  `end` int(11) NOT NULL default '0',
  `winner` int(11) NOT NULL default '0',
  `genre_1` int(11) NOT NULL default '0',
  `genre_2` int(11) NOT NULL default '0',
  `genre_3` int(11) NOT NULL default '0',
  `genre_4` int(11) NOT NULL default '0',
  `genre_5` int(11) NOT NULL default '0',
  `genre_6` int(11) NOT NULL default '0',
  `genre_7` int(11) NOT NULL default '0',
  `genre_8` int(11) NOT NULL default '0',
  PRIMARY KEY  (`weekID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

 

I was trying to decide between that, or adding yet another table to store just genreID and points, so that when I add a new genre I don't have to update the table. Not sure if it's reasonable, or worth it.

 

Thoughts?

Link to comment
https://forums.phpfreaks.com/topic/40432-how-would-you-do-this-table/
Share on other sites

I'd add that second table.  Build a scalable solution now and you can forget about it later.

 

One of the tables from our <shudder> dbase server application at work has 100 additional columns, Plan1 through Plan50 and then sqft1 through sqft50.

 

I look at it and honestly can't believe anyone ever set it up that way to begin with.

Hmm you may need two tables. The genre entries suggest that you have a many-to-many relationship between weeklyPoints and genre. A single weekly point entry can have one to many genres while a single genre can be included on 1 or more week

 

You could also give each genre a name too.

 

For example:

 

weeklypoints

==========

id

start

end

winner (is winner a foreign key to a person table?)

 

weeklypoints_genre

===============

id

weeklypoints_id

genre_id

 

genre

====

id

title

 

No, winner is a genre, 1-8.

 

Normally I would have done it the way you guys are suggesting, I was just thinking this time that it might be easier this way.

 

roopurt - I see what you mean, it makes sense for the first time when there's only 5 groups, but then they keep getting added and added.

 

Thanks guys, I'll change it now.

NEVER design tables that will mean changing that table design to accomodate extra recurring fields. Normalize it with the second table.

 

If you don't then not only do you need to keep altering the table but also need to change your code too with every table change.

 

(Depends on the terms of your maintenance contract I suppose - it could provide  steady income ;) )

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.