Jump to content

5 Star rating store in database

- - - - -

  • Please log in to reply
5 replies to this topic

#1
vikaspa

vikaspa

    Newbie

  • Members
  • Pip
  • 1 posts
Dear All

Need code to have 5 star ratings

event want 1.5, 2.5 etc (half star )
and way to store it in table
(how to get values so as to store in database)

#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#
five stars is just to store a integer 0-5. if you want half steps, just do 0-10 and divide it to half when displaying, or just let it be stored and used as 0-10. this must be easiest.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#3
masterphp

masterphp

    Newbie

  • Members
  • Pip
  • 2 posts
Why not you just store it with floating point and when needed, fetching it and by if-else you can use css.

#4
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#
Floating point variables are always trickier, takes more memory and can end up in tiny rounding errors if used in some ways. I'd say, stay away from them if you can.

Example: 1/3 * 3 with floats is 0.9999999999 and if calculated correctly with ints 1, and those aren't equal.

You can easiest use a table converting (looking up) the number to the right html with a simple command instead of ridicilous if-else chains which is harder to follow.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#5
masterphp

masterphp

    Newbie

  • Members
  • Pip
  • 2 posts
We can also use number_format() before inserting mySQL that solve the problem of floating point and i am not use your second option instead of if-else. You can elaborate it. I am learning php :lol:

#6
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#
I don't understand what you mean about my second thing?
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users