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?
star rating in British English (stɑː ˈreɪtɪŋ ) a rating indicated by stars (usually 1–5), the highest number of stars indicating the best quality, highest amount etc. Some suncare products carry a star rating for UVA protection. Collins English Dictionary.
There are three options:
The first option is the most portable, since the maximum value and the representation of the rating are entirely client-side (client-side as far as the database is concerned, not client-side as in it's done at the user's machine).
The second just seems arbitrarily complex, unless you wish to continue to display a 7/10 rating as a 7 with 10 stars rather than a 14 with 20 stars.
The third requires the least up-front work, but requires a massive database update when changes are made to the rating scale.
Just to reiterate, I recommend storing the value as a float
or double
in the database and applying whatever scale is appropriate on the client side..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With