Jump to content

5 star rating - calculation help


Speedy84

Recommended Posts

I want to set up a 5 star rating system on my site. But I need some help with the calculations.. all I can come up with at this point is create a column in the db called "points" and one called "totaltvotes" and then do something like "points/totalvotes".. but i'm positive that this is wrong =)

Link to comment
Share on other sites

Careful with that, ya might get a divide by zero

$rating = round(($points && $totalvotes)?($points / $totalvotes):0);

 

is all u need, cuz ya only have 1 - 5 as a scale

so dividing the total points by total votes will still give u a range of 1 - 5

using the round function well makes shure yer at a whole number

 

switch($ratiing)
{
  case 1:
      // 1 star
      break;
.
.
  default:
      // no stars
}

 

or use if/ifelse/else structure

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.