In order to curiosity:
In the case of weight of an object in "very light", "light", "medium", "heavy" and "very heavy". We can use some statistical methods to define a range.
So if we have 50 products, with the following weight listing:
1, 1, 3, 4, 4, 5, 5, 6, 6,
7, 7, 7, 7, 7, 8, 8, 8, 9, 9,
10, 10, 10, 11, 15, 16, 16, 16, 17,
18, 18, 18, 18 ,18, 40, 40, 40, 40, 40,
47, 47, 47, 49, 49, 50, 55, 58, 59, 90.
We have the highest value as 90 and the lowest as 1, so our sampling amplitude is AA = 89 (90 - 1).
Then we calculate i, which theoretically would be the amount of clusters we need to have: i = 1 + 3.3 log 50 = 6.6 ~ 7 (normal rounding).
Therefore the ideal would be to have 7 weight ratings, but for this example we will use the 5 already classified by you, so consider i = 5.
We now need to calculate what the intervals will be
AA / i = 89/5 = 17,8 ~ 18 (always rounded up).
Very Light: 1 |- 19
Light: 19 |- 37
Medium: 37 |- 55
Heavy: 55 |- 73
Very Heavy: 73 |- 91
<?php
abstract class Peso
{
public getStringValue($value)
{
if ($value < 19){
return "Muito Leve";
}elseif($value < 37){
return "Leve";
}elseif($value < 55){
return "Médio";
}elseif($value < 73){
return "Pesado";
}else{
return "Muito Pesado";
}
}
}
?>
It depends on how you use it in the application. I always create a table of type Sex:[id, name]. So I have it represented with both number and string.
– Franchesco
@Earendul this id would be given by me or this is an id type INTEGER NOT NULL AUTO_INCREMENT used to be primary key
– Ricardo
@Earendul I think that your comment is worth an answer. : ) Because, storing directly in literal form generates difficulties with localization (presentation in different languages).
– Luiz Vieira
@Ricardohenrique Since there are probably only 2 records (’M' and 'F') you can define the number yourself, and it can be a primary key since there will never be two equal numbers and you can relate to other tables
– Franchesco
Creating a table to let eternally with 2 records just wouldn’t be a bit pointless ? Isn’t it more practical, easy, functional to establish this via code ? Constant or Enum ???
– Guilherme Branco Stracini
You will spend a table on your DBMS, you will have to query (selects and joins), process the query and the result just to prove something you already know ? After all it was you who populated the table and it is not changed... PHP does not have the Enum structure, but we can easily implement it this way: http://stackoverflow.com/questions/254514/php-and-enumerations
– Guilherme Branco Stracini