I am trying to execute
SELECT * FROM `product_laptop` WHERE name = "Acer Sdfsdf"
MySQL returned an empty result set (i.e. zero rows). (Query took 0.0010 seconds.)
even though there is an entry with the name Acer Sdfsdf` and name is also defined as unique key.
Maybe you should try like
to get the correct data:
SELECT * FROM `product_laptop` WHERE name LIKE "Acer%"
Would that suit your needs?
The =
requires an exact match, using like
with the %
wildcard will give you the results you want. This won't match exact records though and will allow for all sorts of variations.
SELECT * FROM `product_laptop` WHERE name like "Acer%Sdfsdf"
With LIKE you can use the following two wildcard characters in the pattern:
% matches any number of characters, even zero characters.
_ matches exactly one character.
http://dev.mysql.com/doc/refman/5.7/en/string-comparison-functions.html
You can use:
$name = preg_replace('/\s+/', '%', trim($name));
to convert all whitespaces to wildcards.