MySQL query: return rows where field is made of characters from the given php string
I am looking for a mysql query which will return me all the rows,
where a particular field is made up of characters from a given string.e.g. I 've this string: $input = 'abcdef';
'name'
consists of letters from $input
.
I hope I have expressed myself clearly.. :)
EDIT: Also, for the query you suggest, will it really improve performance, if we are just searching for strings made of letters a-z instead of some patterns, esp. when we are requesting data every 2 seconds.
The thing is that for now, my requirements are to only search among numeric, alpha or alphanumeric formats.. I will be 开发者_StackOverflow社区using the exclusive patterns later on.Regards
Nikhil Gupta$query = "SELECT * FROM table WHERE `name` REGEXP '[" . mysql_real_escape_string($input) . "]'";
But this query is really weird and will be very slow (depends on how many rows you have).
SELECT `name` FROM `table` WHERE `name` REGEXP '^[abcdef]*$'
See MySQL: Regular expressions.
精彩评论