如何在5星评级系统中使用php喜欢和不喜欢转换?

问题描述:

Let's say i have a database entry like this:

video_id | likes | dislikes

 654         5          12

What i want to do is to transform the number of likes and dislikes into a 5 stars rating for google rich snippets.

Do you have any ideas? Some code?

假设我有一个这样的数据库条目: p>

   video_id | 喜欢| 不喜欢
 
 654 5 12 
  code>  pre> 
 
 

我想做的是将喜欢和不喜欢的数量转换为 google rich snippets 。 p>

你有什么想法吗? 一些代码? p> div>

To get a rating between 1 and 5, you could do the following:

$rating = 1 + 4 * $likes / ($likes + $dislikes);

Remember to take special care of the case where there are no votes, though.