0

the user saved on database ahmedhatem

SELECT personal_data.fname
    FROM
    personal_data
    WHERE
    ( personal_data.fname  LIKE '%ahmed hatem%' or
    Replace(ahmed hatem , ' ', '')
      LIKE '%ahmed hatem%' 

when i use ahmedhatem the result going well but i need this sql to find the ahmedhatem
what can i do ? i tried to use

personal_data.fname 
  LIKE '%ahmed hatem%' 

but it doesn't work

3 Answers3

0

This question as already been asked. How to remove leading and trailing whitespace in a MySQL field? You can use TRIM() function.

Community
  • 1
  • 1
Kilowog
  • 192
  • 1
  • 10
  • but i need to remove the spaces from the result come from form filed .. and change ahmed hatem with $name that mean if the user start to search about ahmed hatem and the name in tha database saved as ahmedhatem he can find it .. i tried trim but i didn't got the result – Abdelrahman Magdy Aug 05 '15 at 11:56
  • This is working for me `SELECT * FROM 'personal_data' WHERE fname LIKE replace('ahmed hatem', ' ','')` You can even add % `SELECT * FROM 'personal_data' WHERE fname LIKE replace('%med hatem', ' ','')` – Kilowog Aug 05 '15 at 12:13
0

You can you percent sign as "any amount of any characters" wherever you want

SELECT personal_data.fname
FROM
personal_data
WHERE
 personal_data.fname  LIKE '%ahmed%hatem%'
Vladimir_M
  • 136
  • 6
0

Use this TRIM function to remove all whitespaces

aldrin27
  • 3,407
  • 3
  • 29
  • 43