Sorting String as Numbers ie (1,100,2) >> (1,2,100)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    Sorting String as Numbers ie (1,100,2) >> (1,2,100)

    Casting...yes, i know. that's what most of you guys will go for....aaand i'll try it but here's what my data looks like:

    10
    100D
    203(A.b)
    203(A.c)
    340A
    399
    500

    I'm scared that SOME might even have the letter BEFORE the number

    obvious way to do this is with (int) type casting

    (for those who have the same problem but without the letters, try that)

    Is there a better way than this for my data?

    FYI the numbers are in MySQL table, if it can be done query-level, let me also.

    Thanks,

    DM
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Expected behavior of cast in php according this guy:

    This small tutorial shows you how to convert PHP string to int value.


    is
    • "10" -> 10
    • "10.5" -> 10
    • "10,5" -> 10
    • "10 " -> 10
    • " 10 " -> 10
    • "10test" -> 10
    • "test10" -> 0
    And come to think of, that behavior is acceptable.

    Because, those that start with letters go to the beginning (as they should) if sorted ASC and

    203A
    203(34)
    etc...

    will be next to each other in the sort, which gives me a better sort than what i have now.

    STILL!! FEEL FREE to give more ideas, its 99% solved for me though.

    Comment

    Working...