jasonc Posted October 14, 2011 Share Posted October 14, 2011 How would I get all results returned to be in order by letter then numbers after and then the other characters. i.e. apple bet coat dig 014 156 467 987 .abc and so on... Quote Link to comment https://forums.phpfreaks.com/topic/249113-get-results-in-alphanumric-order-but-letters-first-then-numbers-and-other-char/ Share on other sites More sharing options...
AyKay47 Posted October 14, 2011 Share Posted October 14, 2011 where are these result coming from? a database? array? Quote Link to comment https://forums.phpfreaks.com/topic/249113-get-results-in-alphanumric-order-but-letters-first-then-numbers-and-other-char/#findComment-1279298 Share on other sites More sharing options...
jasonc Posted October 14, 2011 Author Share Posted October 14, 2011 sorry from mysql Quote Link to comment https://forums.phpfreaks.com/topic/249113-get-results-in-alphanumric-order-but-letters-first-then-numbers-and-other-char/#findComment-1279301 Share on other sites More sharing options...
AyKay47 Posted October 14, 2011 Share Posted October 14, 2011 use the ORDER BY clause on the end of your query and specify the row that you want to order your results by Quote Link to comment https://forums.phpfreaks.com/topic/249113-get-results-in-alphanumric-order-but-letters-first-then-numbers-and-other-char/#findComment-1279302 Share on other sites More sharing options...
jasonc Posted October 14, 2011 Author Share Posted October 14, 2011 I have the order by already but it orders the list by numbers and then letters. But I am wanting to have it ordered by letters first then numbers then other characters. Quote Link to comment https://forums.phpfreaks.com/topic/249113-get-results-in-alphanumric-order-but-letters-first-then-numbers-and-other-char/#findComment-1279331 Share on other sites More sharing options...
AyKay47 Posted October 14, 2011 Share Posted October 14, 2011 Note: this is untested.. SELECT * FROM table_name ORDER BY LEFT(col_name,1) > 0, left(col_name,1), substring(col_name,2) > 0 Quote Link to comment https://forums.phpfreaks.com/topic/249113-get-results-in-alphanumric-order-but-letters-first-then-numbers-and-other-char/#findComment-1279335 Share on other sites More sharing options...
jasonc Posted October 14, 2011 Author Share Posted October 14, 2011 Note: this is untested.. SELECT * FROM table_name ORDER BY LEFT(col_name,1) > 0, left(col_name,1), substring(col_name,2) > 0 I just tried this query and seems to work, only thing is that it shows like so 0 (zero) a b c d ... 1 2 3 4 Quote Link to comment https://forums.phpfreaks.com/topic/249113-get-results-in-alphanumric-order-but-letters-first-then-numbers-and-other-char/#findComment-1279340 Share on other sites More sharing options...
jasonc Posted October 14, 2011 Author Share Posted October 14, 2011 how would I get it to show... a b c d ... 0 (zero) 1 2 3 4 Quote Link to comment https://forums.phpfreaks.com/topic/249113-get-results-in-alphanumric-order-but-letters-first-then-numbers-and-other-char/#findComment-1279374 Share on other sites More sharing options...
fenway Posted October 14, 2011 Share Posted October 14, 2011 You can use the boolean result of REGEXP. Quote Link to comment https://forums.phpfreaks.com/topic/249113-get-results-in-alphanumric-order-but-letters-first-then-numbers-and-other-char/#findComment-1279381 Share on other sites More sharing options...
jasonc Posted October 14, 2011 Author Share Posted October 14, 2011 i searched 'REGEXP' and looked to find it on php.net/REGEXP but can find out how i do this ? Quote Link to comment https://forums.phpfreaks.com/topic/249113-get-results-in-alphanumric-order-but-letters-first-then-numbers-and-other-char/#findComment-1279387 Share on other sites More sharing options...
fenway Posted October 14, 2011 Share Posted October 14, 2011 No, MYSQL's REGEXP -- you can determine if your values are all digits or not. Quote Link to comment https://forums.phpfreaks.com/topic/249113-get-results-in-alphanumric-order-but-letters-first-then-numbers-and-other-char/#findComment-1279399 Share on other sites More sharing options...
jasonc Posted October 14, 2011 Author Share Posted October 14, 2011 looking at mysql these are the entries... 0.5L Cliptop Jar 0.5L Kilner Preserve Jar Animal Ice Packs 3 Character Cells Ant Killer Gel Accents Brushed Stainless Steel 2 Slice Toaster This is how they show, this is only a snippet of my data of course, but just to show where it is going wrong. Quote Link to comment https://forums.phpfreaks.com/topic/249113-get-results-in-alphanumric-order-but-letters-first-then-numbers-and-other-char/#findComment-1279401 Share on other sites More sharing options...
fenway Posted October 14, 2011 Share Posted October 14, 2011 Well, you can order by if the first character is alpha or digit. Quote Link to comment https://forums.phpfreaks.com/topic/249113-get-results-in-alphanumric-order-but-letters-first-then-numbers-and-other-char/#findComment-1279476 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.