views:

23

answers:

1

So, I'm trying to learn a lot at once, and this place is really helpful!

I'm making a little running log website for myself and maybe a few other people, and I have it so that the user can add workouts for each day. With each workout, I have a variety of information the user can fill out for the workout, such as running distance, time, quality of run, course, etc... I store this in a MySql database as a table with fields titled "distance", "time", "runquality", etc... Now, these field titles don't match up with what I want displayed on the running log, so I was thinking of using the "Comments" attribute for a field to store its human-readable title--thus the field "runquality" would have "Quality of run" as its comment, and then I would pull the comment with a SQL query and display it instead of the field name. Is this a good theoretical/practical way of going about it? And what sort of SQL would I use to pull the comment for the field anyway?

Secondly, suppose I want to add the ability for the user to create their own workout descriptors. So say a user wants to add a "temperature" descriptor for their workout. Should I create a script that adds fields to my workout table, or should I create a separate table listing only workout descriptors and somehow link the descriptor table with the "contents" table? I haven't learned any theory about database design or anything so any help is appreciated!

+1  A: 

You should avoid mixing metadata and data. The "Comments" field attribute is metadata. This is really just a note for the developer. Accessing metadata from a program is called reflection. There's no need for reflection in your case, and it will complicate things.

Keep it simple by simply naming the headers in the application code. There's no need to use the field name as the heading. If you build a translation table, it will be even better, so that you can easily support other languages.

For example, you know that the "Phone" field is really "Telephone Number", so you use that as your heading, and you might have a translation table that you look up each time when you build the view. "Telephone Number" will return "Telephone Number" for English, and "Telephono Numero" for another language.

Marcus Adams