Search code examples
phpmysqlsqlsql-like

PHP-MySql: Like Query with modified Table Column


I have a column in a database table with a code LIKE this: 12 34 56

In my php page I have a text form for find the code AND the query is:

SELECT column as colmn_find FROM CER WHERE column LIKE '%".$term."%';

How I search the code also without the white spaces?

So if i find 12 34 is the same of 1234


Solution

  • SELECT column as colmn_find 
    FROM CER 
    WHERE REPLACE(column, ' ', '') LIKE '%YOURTERM%';
    

    Replace the spaces in your where clause with nothing and it will be treated as if it had no spaces in your search.