Very simple ratings script.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mykg4orce
Forum Newbie
Posts: 21
Joined: Tue May 28, 2002 2:19 pm

Very simple ratings script.

Post by mykg4orce »

Ok i want to make a simple rating script. basically i will have the user choose a value between 10 and 0 from like a radio button or drop down menu, and that info will be fed into a MySQL Column, ok so then once i have lets say a few of these ratings done by differnt users how do calculate an overall average?

|------------------|
|ID|Message|Rating|
|------------------|
|1|hello|2|
|2|hi|9|
|3|yo man|7|
|4|homes|10|
|------------------|

ok so lets my table looks like that....how do i use the numbers from the "Ratings" column to display an overall average?

thank you!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I'd try the AVG(expr) function on rating ;)
mykg4orce
Forum Newbie
Posts: 21
Joined: Tue May 28, 2002 2:19 pm

Post by mykg4orce »

thanks mate! :)
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post by lc »

I think what I'd do is keep 2 numbers in a database.
1 the total of all votes added up
2 the total nr of votes

Oh and I do believe I remember that php doesn't work with 9.5 and such so I might use 10 in stead of 1 in the script just to make it work more detailed.

That should be easy enough to make a script do.

Then just divide one by the other. And put a dot in at the right place.
Post Reply