phpmysqlsortingnatsort

Php natsort by 2 dimensions array


I've the following sql: SELECT s.flat, s.name FROM source s. Flat may contains flats with delimiter like 1/5 or 1/2, and I can not use numeric fileld in this case. In the result I get sorting like this:

1 Bob, 
10 Joe, 
11 Tim, 
12 Lisa, 
2 Ira, 
21 Tom, 

How can I use natsort() method for 'flats' part with saving 'name' part?


Solution

  • This should do a pretty good job of it:

    SELECT s.flat, s.name FROM source s ORDER BY CAST(s.flat AS UNSIGNED)
    

    Demo