binarylime Posted February 17, 2008 Share Posted February 17, 2008 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. Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted February 17, 2008 Share Posted February 17, 2008 like looks for entry to be included with in the field Example if the field had aaandrewaaa and you search for andrew then it would find both aaandrewaaa and andrew not the other way around. Quote Link to comment Share on other sites More sharing options...
binarylime Posted February 17, 2008 Author Share Posted February 17, 2008 Nice one, thanks for that. I understand now. So is there any way of this working the other way around? Where it would match a user entry of aaandrewaaa if andrew was stored in the database? Thanks. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 17, 2008 Share Posted February 17, 2008 SELECT * FROM item WHERE INSTR('$entry', firstname) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.