Convert fields with database or in code?
Posted: Fri Dec 15, 2006 2:33 pm
Suppose I've got code values for a particular field in my db. For instance, suppose the field's name is 'color', and possible values are 0, 1, 2, 3, etc.
If the field has a value of 0, that means it is blue.
1=yellow
2=green
3=black
etc
From a development standpoint, is it better to have a method that converts them
ie
Or is it better to have these conversions in a database table?
I'm inclined to think it's better to have a table with 2 columns (code and color), then you can make a UI so users can add/modify/delete colors, but I'm wondering if there's an industry standard. Thanks in advance
If the field has a value of 0, that means it is blue.
1=yellow
2=green
3=black
etc
From a development standpoint, is it better to have a method that converts them
ie
Code: Select all
if($color == 1)
$returnval = "yellow";
if($color == 2)
$returnval = "green";
return $returnval;I'm inclined to think it's better to have a table with 2 columns (code and color), then you can make a UI so users can add/modify/delete colors, but I'm wondering if there's an industry standard. Thanks in advance