Jump to content

Match using LIKE


binarylime

Recommended Posts

Hey guys,

 

I'm trying to build a query to search a user table for matches as follows:

 

"select firstname, lastname, username from user where firstname like %'$firstname'% and lastname like  %'$lastname'% and institutename='$institute' and moderator='0'"

 

If i enter an exact match, I get the results returned as expected, but if i add extra letters to the beginning or the end of the value i get no results.

 

So for example, if Andrew is in my database, i want the query to match aaandrewaaa etc..

 

I've not found an example of using a variable in a like query so i'm not sure if it's correct. I've tried '%firstname%' and %'firstname'% but no luck...

 

Any ideas?

 

Many thanks.

Link to comment
https://forums.phpfreaks.com/topic/91526-match-using-like/
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.