SteveCatbert Posted January 7, 2016 Share Posted January 7, 2016 Hi, I am working on a range script where the range consists of values ranging from 01A, 01B, 01C..... 05A, 05B.... 11A, 11B, 11C, etc. Is there a way to filter out a range such as this so if I wanted to, say, select all values between 1A-5D, would that be possible? Is there a way to manipulate the range function to accomplish this? Quote Link to comment https://forums.phpfreaks.com/topic/300213-range-with-letters-and-numbers/ Share on other sites More sharing options...
Jacques1 Posted January 7, 2016 Share Posted January 7, 2016 (edited) The range() function cannot do this (unless you were to convert the strings into numbers, which is cumbersome). But you can use a for loop: for ($str = '1A'; $str <= '5D'; $str++) { var_dump($str); } Edited January 7, 2016 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/300213-range-with-letters-and-numbers/#findComment-1529232 Share on other sites More sharing options...
SteveCatbert Posted January 7, 2016 Author Share Posted January 7, 2016 I need to put this into a mysql query where only values between 1A and 5D would show up (including 1A and 5D). Do you know how to this could be accomplished? Quote Link to comment https://forums.phpfreaks.com/topic/300213-range-with-letters-and-numbers/#findComment-1529247 Share on other sites More sharing options...
Solution Barand Posted January 7, 2016 Solution Share Posted January 7, 2016 SELECT whatever FROM mytable WHERE mycol BETWEEN '1A' AND '5D' Quote Link to comment https://forums.phpfreaks.com/topic/300213-range-with-letters-and-numbers/#findComment-1529248 Share on other sites More sharing options...
SteveCatbert Posted January 7, 2016 Author Share Posted January 7, 2016 I feel like an idiot now. Thank you very much, that did it. Quote Link to comment https://forums.phpfreaks.com/topic/300213-range-with-letters-and-numbers/#findComment-1529249 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.