|
|||||||
| PHP Discussion and technical support for using and deploying PHP based websites. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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
|
||||
|
||||
|
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
|
||||
|
||||
|
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
|
||||
|
||||
|
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
|
||||
|
||||
|
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
|
||||
|
||||
|
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:
__________________
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
|
|||
|
|||
|
Quote:
if the field is a numberic type field, the sort is performed on the basis of the numerical value of the field. |
|
#8
|
||||
|
||||
|
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. |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|