Jump to content


Photo

Sorting output


  • Please log in to reply
2 replies to this topic

#1 aeris130

aeris130
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 20 March 2006 - 06:15 PM

Here's my query:

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

"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:
1

106

2

25

305

4

8

88

9

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?

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 20 March 2006 - 06:31 PM

If the values are truly numbers, change the datatype to int instead of varchar.

Info: PHP Manual


#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 20 March 2006 - 06:31 PM

The filed needs to be of a numerical type like INT, not VARCHAR.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users