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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.