Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to avoid Space sensitivity of MySQL data

I have a record like "John Carter" with the space between two names. Now I want to search the word with the help of WHERE condition like (WHERE NAME="JohnCarter") without space, but due to the space sensitivity query returns me false, so is there any solution to avoid this space sensitivity.

Id name
1 John Carter
2 Rosy Foster

$name=’JohnCarter’;
$result=mysqli_query($con,"SELECT * FROM profile WHERE name=’$name’");
if(mysqli_num_rows($result)>0){
echo ‘true’;}else{echo ‘false’}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This seems to be the ideal situation to use a soundex function. MySQL has such a function builtin:

mysql> select soundex('John Carter'), soundex('JhonCarter');
+------------------------+-----------------------+
| soundex('John Carter') | soundex('JhonCarter') |
+------------------------+-----------------------+
| J52636                 | J52636                |
+------------------------+-----------------------+

See also:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading