moisesbr Posted August 20, 2013 Share Posted August 20, 2013 Hi I trying the search using the query below: $result = mysql_query("SELECT * FROM certificado WHERE nome='$name' ") or die (mysql_error()); If I look for Jose da Silva in table,it only works if I type full name. "Jose da Silva" .How can I make the query work by typing part of search string, as "Jose da", "Jose d", etc. Moises Quote Link to comment https://forums.phpfreaks.com/topic/281401-search-by-part-of-string/ Share on other sites More sharing options...
.josh Posted August 20, 2013 Share Posted August 20, 2013 SELECT * FROM certificado WHERE nome LIKE '%{$name}%' Quote Link to comment https://forums.phpfreaks.com/topic/281401-search-by-part-of-string/#findComment-1445997 Share on other sites More sharing options...
moisesbr Posted August 20, 2013 Author Share Posted August 20, 2013 SELECT * FROM certificado WHERE nome LIKE '%{$name}%' Very useful command, but if name is Elton John, and I search "John", Elton John is found as well. I need Elton John is found only if a type: "Elto" "Elton" "Elton J", etc. Moises Quote Link to comment https://forums.phpfreaks.com/topic/281401-search-by-part-of-string/#findComment-1446000 Share on other sites More sharing options...
QuickOldCar Posted August 20, 2013 Share Posted August 20, 2013 If searched for John and Elton John comes up, the search works, it wouldn't work so well otherwise. If you needed more control and wanted to spend the time more advanced and multiple search queries, fulltext search is a better way. http://dev.mysql.com/doc/refman/5.7/en/fulltext-search.html Fulltext Boolean can do things matching against,within,excluding,stemming,weighted and so on. http://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html Quote Link to comment https://forums.phpfreaks.com/topic/281401-search-by-part-of-string/#findComment-1446003 Share on other sites More sharing options...
AbraCadaver Posted August 20, 2013 Share Posted August 20, 2013 If searched for John and Elton John comes up, the search works, it wouldn't work so well otherwise. If you needed more control and wanted to spend the time more advanced and multiple search queries, fulltext search is a better way. http://dev.mysql.com/doc/refman/5.7/en/fulltext-search.html Fulltext Boolean can do things matching against,within,excluding,stemming,weighted and so on. http://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html Also, maybe consider 'lastname', 'firstname' and 'middlename' columns. Easier to concatenate those than try to guess a split on one column. Quote Link to comment https://forums.phpfreaks.com/topic/281401-search-by-part-of-string/#findComment-1446008 Share on other sites More sharing options...
.josh Posted August 20, 2013 Share Posted August 20, 2013 Very useful command, but if name is Elton John, and I search "John", Elton John is found as well. I need Elton John is found only if a type: "Elto" "Elton" "Elton J", etc. Moises but...that's exactly what you said you wanted, yes? If you want it to match starting at beginning of string, instead of anywhere within string, then remove the first % Quote Link to comment https://forums.phpfreaks.com/topic/281401-search-by-part-of-string/#findComment-1446009 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.