Garethp Posted November 4, 2008 Share Posted November 4, 2008 Well, I'm creating a website and I want to search a for a field that contains a certain string of characters. I have tried the following $Look = mysql_query("SELECT * FROM table WHERE column LIKE '$Search'"); and $Look = mysql_query("SELECT * FROM table WHERE CONTAINS (column, '$Search')"); but when I try to run it through if(!mysql_num_rows($Look)) It either comes out as no results or not a valid resource. Can I get some help please? Quote Link to comment https://forums.phpfreaks.com/topic/131317-mysql-contains/ Share on other sites More sharing options...
Adam Posted November 4, 2008 Share Posted November 4, 2008 try adding %s: $Look = mysql_query("SELECT * FROM table WHERE column LIKE '%{$Search}%'"); Quote Link to comment https://forums.phpfreaks.com/topic/131317-mysql-contains/#findComment-681903 Share on other sites More sharing options...
Garethp Posted November 4, 2008 Author Share Posted November 4, 2008 Thanks, works like a charm. Just wandering, what does the %{}% do? What does it change? Quote Link to comment https://forums.phpfreaks.com/topic/131317-mysql-contains/#findComment-681986 Share on other sites More sharing options...
Adam Posted November 4, 2008 Share Posted November 4, 2008 It searches the field for the matching string with 'any number of characters in the pattern' (at each side of it) .. Basically just a wildcard character.. Adam Quote Link to comment https://forums.phpfreaks.com/topic/131317-mysql-contains/#findComment-682021 Share on other sites More sharing options...
luca200 Posted November 5, 2008 Share Posted November 5, 2008 Just to point out: the wildcard characters are '%'. Curly braces are just containers for your variable ($Search) inside the string. You could avoid them and get the same result (in this case) Quote Link to comment https://forums.phpfreaks.com/topic/131317-mysql-contains/#findComment-682958 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.