A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: PHP sorting numbers....

  1. #1
    YH Jelly Llama Jockey defuzz's Avatar
    Join Date
    May 2001
    Posts
    464
    hello, proably quite simple but hope you can help with out too much ridicule.....

    I am doing a php/mysql query that returns a column of numbers ordered by their id. At the moment it is sorting it numerically but is sorting it like this:

    1
    11
    12
    15
    19
    2
    20
    21
    22
    23
    27
    3
    30
    31
    4
    5
    6


    but I want 1,2,3,4,5,6,7,8,9,10,11 etc etc

    what am I doing wrong?

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    if it is mysql sorting them with an order by, you probably have declared the id as a text rather than numeric column.
    If you are sorting in php, try
    sort($array, SORT_NUMERIC)

    at least this is what I get from RTFM ...

    Musicman

  3. #3
    YH Jelly Llama Jockey defuzz's Avatar
    Join Date
    May 2001
    Posts
    464
    hmm, I've already set ID to be "int" but it makes no difference.

    I probably AM asking for trouble having a footer like that aren't i.

  4. #4
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    honestly - it just seems to work everywhere else. You are sure that you ORDER BY id ?

    Musicman

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center