codexx Posted January 7, 2007 Share Posted January 7, 2007 Hello Everyone,Just working on a script that lets users rate each other (1 - 10) . I'm not sure if this is the most effective way, but I was thinking of making each vote a new entry, then retrieve them all into an array. After that add all of the array and devide by the total results to get the average. If this is the best solution I know how to add and get the average, just don't know how to implent the results into the array. If this isn't the best solution could you please point me in the appropriate direction :).Thanks Alot,Sean Quote Link to comment Share on other sites More sharing options...
utexas_pjm Posted January 7, 2007 Share Posted January 7, 2007 If you're planning on using a SQL database to store the results you can use the built in aggregator functions (SUM(), AVG(), etc) http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html to expedite your implementation.Best,Patrick Quote Link to comment Share on other sites More sharing options...
codexx Posted January 7, 2007 Author Share Posted January 7, 2007 Thanks for you're quick reply Patrick!Just another quick question so I'm sure I have this correctly.How would this information then be outputted as normally I just use a while and fetch_assoc.So far i've gotten.. $userrating = mysql_query("SELECT AVG(rating) FROM userratings WHERE rated = '".$user."'"); Quote Link to comment Share on other sites More sharing options...
utexas_pjm Posted January 7, 2007 Share Posted January 7, 2007 Use an alias like: [code]$userrating = mysql_query("SELECT AVG(rating) as average FROM userratings WHERE rated = '".$user."'");[/code]Then you can access it just as you would any other column name.Best,Patrick Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.