Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sql Mathematical problem to php

    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

  • #2
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    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!

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    Can you post the sql you have, then I can have something to go on?

  • #5
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    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.

  • #6
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    Sorry, but I think I need to see the table definition to answer that.

  • #7
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Code:
    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.
    PHP Code:
    $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++;

    Last edited by Inigoesdr; 08-10-2007 at 10:10 PM.

  • #9
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #10
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    Ah I understand now, sorry I think I was looking for something more complicated!

  • #11
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    lol sorry , i think i thought there was something more complicated about it as well lol But thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •