Jump to content

Archived

This topic is now archived and is closed to further replies.

aeris130

Sorting output

Recommended Posts

Here's my query:

[code]SELECT * FROM table WHERE column LIKE \"%$trimmed%\" AND approved='yes'
  ORDER BY number ASC[/code]

"number", is a column that stores a certain number (VARCHAR 10, other then ID) that's unique. These numbers range from 1 to 999. The problem is, that the results are sorted based on the first digit, not the entire number.

Say I have these numbers: 1, 2, 4, 8, 9, 25, 88, 106 and 305.

The results get sorted like this:
[code]
1

106

2

25

305

4

8

88

9[/code]

But I want to store them in the correct order (1, 2, 4, 8, 9, 25, 88, 106 and 305).

How do I solve this?

Share this post


Link to post
Share on other sites
If the values are truly numbers, change the datatype to int instead of varchar.

Share this post


Link to post
Share on other sites
The filed needs to be of a numerical type like INT, not VARCHAR.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.