xiao Posted April 15, 2008 Share Posted April 15, 2008 Hi, I was wondering if anyone knows an advanced tutorial about mysql wildcards. I want to search a string of 6 characters with for example the first 2 characters being anything, then "AP" and then another 2 chracters. Do I search like this? WHERE something LIKE '__AP__' Because when I'd search like this: WHERE something LIKE '%AP%' I'd get results like BAPRS4, 9GLAP0, ... Link to comment https://forums.phpfreaks.com/topic/101199-mysql-wildcard-usage/ Share on other sites More sharing options...
rhodesa Posted April 15, 2008 Share Posted April 15, 2008 try: WHERE SUBSTR(something,3,2) = 'AP' Link to comment https://forums.phpfreaks.com/topic/101199-mysql-wildcard-usage/#findComment-517653 Share on other sites More sharing options...
xiao Posted April 15, 2008 Author Share Posted April 15, 2008 oh, so multiple underscores won't work? Link to comment https://forums.phpfreaks.com/topic/101199-mysql-wildcard-usage/#findComment-517667 Share on other sites More sharing options...
rhodesa Posted April 15, 2008 Share Posted April 15, 2008 I've never used or seen someone use an underscore as a wildcard before Link to comment https://forums.phpfreaks.com/topic/101199-mysql-wildcard-usage/#findComment-517680 Share on other sites More sharing options...
xiao Posted April 15, 2008 Author Share Posted April 15, 2008 I found it while searching for wildcard. I just found this: http://www.htmlite.com/mysql011.php It says: The underscore wildcard can be used a number of times to find a specific number of characters. Example, this would be used in an equation to return a value of 'Stan' plus 3 characters (since there are 3 underscores)... $sql = mysql_query("SELECT * FROM address_book WHERE last_name LIKE 'Stan___'"); while ($row = mysql_fetch_row($sql)) { echo "$row[0] $row[1] $row[2] <br />"; } So I guess multiple underscores will work Link to comment https://forums.phpfreaks.com/topic/101199-mysql-wildcard-usage/#findComment-517689 Share on other sites More sharing options...
gluck Posted April 15, 2008 Share Posted April 15, 2008 I found it while searching for wildcard. I just found this: http://www.htmlite.com/mysql011.php It says: The underscore wildcard can be used a number of times to find a specific number of characters. Example, this would be used in an equation to return a value of 'Stan' plus 3 characters (since there are 3 underscores)... $sql = mysql_query("SELECT * FROM address_book WHERE last_name LIKE 'Stan___'"); while ($row = mysql_fetch_row($sql)) { echo "$row[0] $row[1] $row[2] <br />"; } So I guess multiple underscores will work should work Link to comment https://forums.phpfreaks.com/topic/101199-mysql-wildcard-usage/#findComment-517865 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.