SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sort order question

    I often need to sort a set or subset of records in a table in an arbitrary way and am confused about how to get the order I need using a separate sort field.

    What I would like to do is sort like this:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12

    Mysql, of course does this:

    1
    10
    11
    12
    2
    3
    etc.

    If I enter a zero before single digits, MYSQL inconveniently deletes it when inserting it into the table.

    Any way I can get it to sort like we learned to count in kindergarten?

    The only option I have found is to use letters, but then I run into the same problem if I am sorting more than 26 items.

    --Kenoli

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by kenoli View Post
    Mysql, of course does this:

    1
    10
    11
    12
    2
    3
    etc.
    No it doesn't. Unless you've defined the sort order column as character instead of numeric. Try changing the column type.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •