www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > PHP

    PHP Discussion and technical support for using and deploying PHP based websites.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 06-26-2003, 10:37 PM
    khayman2001's Avatar
    khayman2001 khayman2001 is offline
    Registered User
     
    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.
    Reply With Quote
      #2  
    Old 06-26-2003, 10:42 PM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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!
    Reply With Quote
      #3  
    Old 06-26-2003, 10:52 PM
    khayman2001's Avatar
    khayman2001 khayman2001 is offline
    Registered User
     
    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.
    Reply With Quote
      #4  
    Old 06-26-2003, 10:59 PM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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!
    Reply With Quote
      #5  
    Old 06-27-2003, 06:45 PM
    khayman2001's Avatar
    khayman2001 khayman2001 is offline
    Registered User
     
    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.
    Reply With Quote
      #6  
    Old 06-27-2003, 09:36 PM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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!
    Reply With Quote
      #7  
    Old 07-02-2003, 10:15 AM
    esm esm is offline
    Registered User
     
    Join Date: Apr 2003
    Location: Atlanta GA
    Posts: 112
    Quote:
    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.
    Reply With Quote
      #8  
    Old 07-02-2003, 09:00 PM
    khayman2001's Avatar
    khayman2001 khayman2001 is offline
    Registered User
     
    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.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 05:19 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.