Poll average/rating?
Posted: Tue Feb 25, 2003 1:27 am
I have serached but there where to many results and none of the posts that I looked at really helped me.
What I need to do is get the average of a Poll(This should be simple I hope
)
What I have is in the MySQL Database I have 10 table rows:
v1
v2
v3
v4
v5
v6
v7
v8
v9
v10
When someone votes(e.g 6) it will update the row(in this case v6) that is the same number as voted.
Now how do I get the average rating for each link? What I have tried is this:
Does anyone have some code or can fix up my code?
Thanks for any help!
If I didn't make sense please tell me.
Thanks
What I need to do is get the average of a Poll(This should be simple I hope
What I have is in the MySQL Database I have 10 table rows:
v1
v2
v3
v4
v5
v6
v7
v8
v9
v10
When someone votes(e.g 6) it will update the row(in this case v6) that is the same number as voted.
Now how do I get the average rating for each link? What I have tried is this:
I got this code from another script. What I'm not sure about is what I put where the ?????'s are...
// Counts how many votes
$votes = $v1 + $v2 + $v3 + $v4 + $v5 + $v6 + $v7 + $v8 + $v9 + $v10;
// Calculates the rating... Don't know what to put for the ?????
$temp_rating = ($votes) ? ????? / $votes : 0 ;
$rating=number_format($temp_rating , 2);
echo "Rating: $rating";
Does anyone have some code or can fix up my code?
Thanks for any help!
If I didn't make sense please tell me.
Thanks