...

View Full Version : sql Mathematical problem to php

2y2d
08-10-2007, 07:02 PM
ok this is just me thinking and the attributes arent those of what i have but just for clarification on how i would do it
ok theres 3 ranks all 3 ranks give an average score this average score is then ordered by lowest first giving an overall rank (avg rounded to nearest 10), like :

5*2*3 / 3 = 10 = 1
4*5*2 / 3 = 11 = 2

I can get this to diplay as a table but all i want is the overall rank to be displayed and also is it possible that two averages might be the same when each rank cant be the same if so would they be classed as the same overall rank?.

Hope this is explained well lol im horrible at explaining things

mcjwb
08-10-2007, 08:56 PM
First of all the average is the sum of the values divided by the number of values, not the multiplication as you have done.
i.e.:
5+2+3/3 = 3.3

Second, you mention sql in the title of your post but you don't mention it anywhere else, should you have?
I would imagine it is possible to get two averages the same, and yes you would class them as the same overall rank.

Any chance of some code, it often helps an explanation!

2y2d
08-10-2007, 09:21 PM
i havent started to code it yet, the sql part i can do its just putting it together to form the php , but what i was wondering was how to make the sql so that 2 overall ranks arent the same like say two people had an average of 10 how would i get to display as this =
player 1 avg = 10 rank 1
player 2 avg = 10 rank 2
i think im just confusing myself further lol but i hope you understand.

mcjwb
08-10-2007, 09:24 PM
Can you post the sql you have, then I can have something to go on?

2y2d
08-10-2007, 09:45 PM
SELECT `CARank`+`SARank`+`DARank`/3 = `Orank`FROM `MainT` Order by `Orank` Desc
it displays =
`CARank` + `SARank` + `DARank` / 3 = `Orank`
1
1
1
But its not showing just one overall rank and if another user has the same i want them to both have seperate ranks.

mcjwb
08-10-2007, 09:52 PM
Sorry, but I think I need to see the table definition to answer that.

2y2d
08-10-2007, 10:01 PM
ok its no problem ill wait till i have something coded in php thanks for the help though i appreciate it :) i just think i need to understand it more lol

Inigoesdr
08-10-2007, 10:07 PM
SELECT (`CARank` + `SARank` + `DARank`) / 3 AS `Orank`, `username` FROM `MainT` ORDER BY `Orank` DESC
Will give you the average for the row, and if you use the result number as the rank they will all have separate ranks. ie.

\$result = mysql_query('SELECT (`CARank` + `SARank` + `DARank`) / 3 AS `Orank`, `username` FROM `MainT` ORDER BY `Orank` DESC');
\$count = 1;
while(\$row = mysql_fetch_assoc(\$result))
{
print \$count . ' - ' . \$row['username'] . '<br />';
\$count++;
}

2y2d
08-10-2007, 10:19 PM
Thank you thats excactly what i was looking for all i have to do is add 2 more fields.
see i have three users all with the same stats (just for testing) but they do all come out as different ranks thanks. :)

mcjwb
08-10-2007, 11:10 PM
Ah I understand now, sorry I think I was looking for something more complicated!

2y2d
08-10-2007, 11:40 PM
lol sorry , i think i thought there was something more complicated about it as well lol But thanks :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum