mysql_query and LIKE '[a-z]%' not working?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chewedtoothpicks
Forum Newbie
Posts: 1
Joined: Wed Nov 24, 2010 9:22 pm

mysql_query and LIKE '[a-z]%' not working?

Post by chewedtoothpicks »

heres the line:

Code: Select all

$query = mysql_query("SELECT * FROM vendors WHERE name LIKE '[a-m]%' ORDER BY name");
the query should return all names starting with characters a-m and sort in asc order right? But for some reason I get no records returned.

If I change [a-m]% to just a% it works for all a records, so it's an issue with using range matching... I thought this was a valid sql matching format?

is it a problem with mysql_query() in php?
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: mysql_query and LIKE '[a-z]%' not working?

Post by McInfo »

Use REGEXP in place of LIKE.

Code: Select all

SELECT * FROM vendors WHERE name REGEXP '^[a-m]' ORDER BY name
Post Reply