Jump to content

Mysql wildcard usage


xiao

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.