php - MySQL "LIKE" search doesn't work -


i've imported .txt database in mysql through "load data infile", , seemed working, problem if search record on db following query:

 "select * hobby name  'beading'" 

it returns 0 rows, while if use

""select * hobby name  '%beading%'" 

it returns 1 row, if exist 1 record name=beading. know depend on?

when using sql like:

you should use wildcard identifier such (or not):

  1. '%word' - return results value ends letters: "word".
  2. 'word%' - reurn results begin letters: "word".
  3. %word% - return results include letters: "word" anywhere.
  4. there more pattern search combination like:

    'abc' 'abc' true

    'abc' 'a%' true

    'abc' 'b' true

    'abc' 'c' false

if want exact match should use:

"select * hobby name='beading'" 

but like 'beading' should work also, spaces issue or case sensitivity porblem.

you need take care of collation case (sensitivity) when want make sure results complete.

say table utf...cs , want make insensitive case search should declare in sql query, example:

select * hobby name collate utf8_general_ci 'beading' 

try testing different approaches , see fits goal best.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -