www.webdeveloper.com
Results 1 to 8 of 8

Thread: Descending Order

  1. #1
    Join Date
    Jan 2003
    Location
    North Dakota
    Posts
    43

    Descending Order

    Ok, I'm trying to make a ranking page, where it lists the top scorers. I have a table worked out, but I'm having trouble figuring out how to order the users. This is the select I'm using: SELECT username, nickname, score FROM users WHERE nickname != "" ORDER BY people DESC but that only orders descending by the first digit, and I have some people in the thousands, and some only in the fifties, so I get an order rank like 9054, 8235, 603, 53, 407, 449, 22.

    I have no clue how to do this further, so any help would be appreciated.
    - Dan

    You wage wars, murder, cheat, lie to us and try to make us believe
    its for our own good, yet we're the criminals. Yes, I am a criminal.

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Try this SQL statement:

    "SELECT username, nickname, score FROM users ORDER BY score DESC";

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  3. #3
    Join Date
    Jan 2003
    Location
    North Dakota
    Posts
    43
    I had the WHERE nickname != "" because in the game I'm writing, people create a character after they recieve the password generated in registration, and if they hadn't created a character yet, (i.e., the nickname of their character would not be blank) then I didn't want them displayed in the rankings.
    - Dan

    You wage wars, murder, cheat, lie to us and try to make us believe
    its for our own good, yet we're the criminals. Yes, I am a criminal.

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Ok, so just add it in:

    "SELECT username, nickname, score FROM users WHERE nickname != "" ORDER BY score DESC";

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  5. #5
    Join Date
    Jan 2003
    Location
    North Dakota
    Posts
    43
    That's what I tried, but it just takes the first digit and sorts by descending that way, not taking into account the number of digits in each number.
    - Dan

    You wage wars, murder, cheat, lie to us and try to make us believe
    its for our own good, yet we're the criminals. Yes, I am a criminal.

  6. #6
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    I don't know SQL well enough to tell you how to do it in that, but you could just read the records into an array and use PHP to sort them, like this:

    PHP Code:
    <?PHP
    $array 
    = array("103","570","315","264","489");
    rsort($array); #sort array from highest to lowest (to sort from lowest to highest, remove the r in rsort -- sort($array); )
    foreach ($array as $value) {
        echo 
    $value."<br>";
    }
    ?>

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  7. #7
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    112
    Originally posted by khayman2001
    That's what I tried, but it just takes the first digit and sorts by descending that way,
    not taking into account the number of digits in each number.
    if the field is a text/char type field, the sort is performed in a left to right sequence. the "numbers" in a text field are not numeric. Non-numeric "numbers" are not used in arithmetic opertions ( add, substract, multiply and divide ), for example, your telephone "number" or social security "number" or account "number."

    if the field is a numberic type field, the sort is performed on the basis of the numerical value of the field.

  8. #8
    Join Date
    Jan 2003
    Location
    North Dakota
    Posts
    43
    Thank you, so much. That was my problem, I had the type set on the field to varchar instead of int. Anyway, thanks a bunch!

    - Dan

    You wage wars, murder, cheat, lie to us and try to make us believe
    its for our own good, yet we're the criminals. Yes, I am a criminal.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles