/    Sign up×
Community /Pin to ProfileBookmark

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.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@pyroJun 27.2003 — Try this SQL statement:

"SELECT username, nickname, score FROM users ORDER BY score DESC";
Copy linkTweet thisAlerts:
@khayman2001authorJun 27.2003 — 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.
Copy linkTweet thisAlerts:
@pyroJun 27.2003 — Ok, so just add it in:

"SELECT username, nickname, score FROM users WHERE nickname != "" ORDER BY score DESC";
Copy linkTweet thisAlerts:
@khayman2001authorJun 27.2003 — 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.
Copy linkTweet thisAlerts:
@pyroJun 28.2003 — 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:

[code=php]<?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>";
}
?>[/code]
Copy linkTweet thisAlerts:
@esmJul 02.2003 — [i]Originally posted by khayman2001 [/i]

[B]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. [/B]
[/QUOTE]


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.
Copy linkTweet thisAlerts:
@khayman2001authorJul 03.2003 — 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!

?
×

Success!

Help @khayman2001 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...