Forum Moderators: coopster

Message Too Old, No Replies

Adding and averaging in Mysql really ...

         

havoc

6:06 am on May 31, 2004 (gmt 0)

10+ Year Member



Ok i have coded myself into a corner heh. I have a php script that reads a bunch of records and it has a rating system.

in the DB it has to fields 1. Score 2. Votes.

In these fields there are total score and how many votes
for eg Score = 80 Votes = 8 . So the rating will be 8.0.

Is there a Mysql query i can use to get the rating from the two fields and display as top rated?

for eg something like

$query = "GET * FROM 'record' WHERE average 'scores', 'vote' DESC";

I thought you can ... but i could be wrong. Thanks in advance.

hughie

4:07 pm on May 31, 2004 (gmt 0)

10+ Year Member



If I am thinking correctly you need to do something like..

$result=mysql_query("SELECT *,(Score/Votes) AS theaverage FROM record ORDER BY theaverage DESC");
hope it helps.

Hughie

havoc

3:57 am on Jun 1, 2004 (gmt 0)

10+ Year Member



interesting but getting a syntax error . I will keep playing .. thanks for the info

havoc

7:03 am on Jun 3, 2004 (gmt 0)

10+ Year Member



Hrmmm Can anyone geta working query, i have tried for a couple of hours still haven't worked out a solution

coopster

3:25 pm on Jun 3, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The query in hughie's solution should not be causing syntax errors. What exactly is the issue you are having?

havoc

3:26 am on Jun 5, 2004 (gmt 0)

10+ Year Member



Ahh there was a " out of place it works now .. thanks a trillion