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
https://forums.phpfreaks.com/topic/131114-5-star-rating-calculation-help/
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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.