/    Sign up×
Community /Pin to ProfileBookmark

Ordering by a number column

Hi,
I am querying a database and and returning the results ordered by a column that contains codes(numbers).
However, the results are not being ordered as I want. I get something like this:

1
10
11
2
3

Its only ordering on the first digit. Does anyone know how to resolve this?
thanks

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliNov 12.2003 — you may want to use ASCENDING aor DESCENDING commands as well in addition to the ORDER BY

.you will have to look up the corrrect syntax in MySQL for ASCENDING or DESCENDING
Copy linkTweet thisAlerts:
@pyroNov 12.2003 — [code=php]#ascending
"SELECT fieldname FROM tablename ORDER BY id"; #default is ASC
#descending
"SELECT fieldname FROM tablename ORDER BY id DESC";[/code]
?
Copy linkTweet thisAlerts:
@damon2003authorNov 12.2003 — I actually had ASC in the original and its still ordering only on the first digit of the number.

I just thought maybe its how the database is set up, could it be that the column is a text column, I dont configure the database
Copy linkTweet thisAlerts:
@pyroNov 12.2003 — Yes, if it is a text column it will not work correctly. You want to make sure that you are using a numeric type for the field (I think varchar will also work).
×

Success!

Help @damon2003 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...