silkfire Posted April 29, 2011 Share Posted April 29, 2011 I know that if you want to make a natural sort with numbers first you just do 'ORDER BY field + 0' but what is it's the other was around and the letter prefix is of variable width? Right now if I do a normal order it comes out like this: EK1023 T15 T18 T2 T24 T4 T7 I want it like this: EK1023 T2 T4 T7 T15 T18 What's the magic query? Quote Link to comment https://forums.phpfreaks.com/topic/235098-natural-sort-letters-first/ Share on other sites More sharing options...
requinix Posted April 29, 2011 Share Posted April 29, 2011 Any way you can store the prefix and number separately? Must you sort it in MySQL or can you do it in PHP? Quote Link to comment https://forums.phpfreaks.com/topic/235098-natural-sort-letters-first/#findComment-1208254 Share on other sites More sharing options...
fenway Posted May 1, 2011 Share Posted May 1, 2011 SUBSTRING_INDEX() is your friend. Quote Link to comment https://forums.phpfreaks.com/topic/235098-natural-sort-letters-first/#findComment-1209137 Share on other sites More sharing options...
silkfire Posted May 1, 2011 Author Share Posted May 1, 2011 I solved it by making 2 columns and letting PHP Regex split the letter and the number part. fenway the letter part is not of fixed width so it wouldn't work. Quote Link to comment https://forums.phpfreaks.com/topic/235098-natural-sort-letters-first/#findComment-1209173 Share on other sites More sharing options...
fenway Posted May 2, 2011 Share Posted May 2, 2011 I solved it by making 2 columns and letting PHP Regex split the letter and the number part. fenway the letter part is not of fixed width so it wouldn't work. There is still a way to do this with locate, but two columns is better anyway. Quote Link to comment https://forums.phpfreaks.com/topic/235098-natural-sort-letters-first/#findComment-1209476 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.