mjahkoh Posted October 15, 2008 Share Posted October 15, 2008 I have a table with a varchar field. The field has integers and alphanumerics. Is there a way to select numbers only Quote Link to comment https://forums.phpfreaks.com/topic/128506-select-integer-values-only-from-a-varchar-field/ Share on other sites More sharing options...
Zane Posted October 15, 2008 Share Posted October 15, 2008 I'm not sure if there's a way to query it such a way to do that....but if you just take the data out as is... you can strip the letters out like this (If of course, there are ONLY letter and numbers) $numbers = (int)implode(preg_split("/[^A-Za-z]/", $mysqlRow, -1, PREG_SPLIT_NO_EMPTY); Quote Link to comment https://forums.phpfreaks.com/topic/128506-select-integer-values-only-from-a-varchar-field/#findComment-665987 Share on other sites More sharing options...
Barand Posted October 16, 2008 Share Posted October 16, 2008 You could use MySQL built in REGEXP function http://dev.mysql.com/doc/refman/5.0/en/regexp.html Quote Link to comment https://forums.phpfreaks.com/topic/128506-select-integer-values-only-from-a-varchar-field/#findComment-667514 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.