What is a mantainable way of saving "star rating" in a database?
Posted
by Montecristo
on Stack Overflow
See other posts from Stack Overflow
or by Montecristo
Published on 2010-04-20T13:41:30Z
Indexed on
2010/04/20
13:43 UTC
Read the original article
Hit count: 206
I'll use the jQuery plugin for presenting the user with a nice interface
The request is to display 5 stars, up to a total score of 10 (2 points per star).
By now I thought about using 7/10
as a format for that value, but what if at some point in the future I'll receive a request like
We would like to give users more choice, let's increase the total score to 20 (so that each star contributes with a maximum of 4 points)
I'll end up with a table with mixed values for the "star rating" column: some will be like 7/10
while others will be like 14/20
.
Is it ok for you to have this difference in the database and deal with it in the logic layer to have it consistent? Or is preferred another way so that querying the table will not result in inconsistent results outside the application?
Maybe floating point values could help me, is it better to store that value as a number less than or equal to one? So in each of the two examples the resulting value stored in the database would be 0,7
, as a number, not a varchar, which can be queried also outside the application.
What do you think?
© Stack Overflow or respective owner