filter data from a small query without spaces

0

How do I query the database that ignores accents and other special characters?

I have the products table that has the name field with the following values:

" shoes", "Tennis", "Karaoke and Videokê", etc ...

No BD product names are accented and separated by space.

My URL: http://meusite.com.br/produtos/calcados

The products page receives the value "calcado" and check if there are products with that name.

The problem is that, because the bank name of the product is recorded with accents and spaces, when I send "shoes" I can not find anything, since I only have " shoes ".

I would also like it to consider composite words like:

Karaoke and Video, Karaoke, Video ...

SQL Query

 $con = $pdo->query("SELECT * FROM ws_cat_sub WHERE sub_categoria = 'calcados' ");
  $return_id = $con->fetch(PDO::FETCH_OBJ);
    
asked by anonymous 27.04.2017 / 22:39

1 answer

0

I do not know if I understand correctly, but I think you want to search the database, but you want the person to search without the accents? If this is the case, the problem is that you should not put a = sign for the results, but rather the LIKE parameter, then your code looks like this:

>
 $con = $pdo->query("SELECT * FROM ws_cat_sub WHERE sub_categoria LIKE '%calcado%' ");
 $return_id = $con->fetch(PDO::FETCH_OBJ);

Explanations:
% = The percentage symbol indicates that you can have a character before or not, ' without C will return the footwear because it searched for a word that looks like one that has been saved in the database, this applies to you also search for calcad, alcado but not for aclcado

LIKE = Like is a substitute for = . If you do not put the LIKE will give error! Below are the references!

NOTE: If this symbol appears: simply use the function utf8_encode or utf8_decode .

REFERENCES:

link link

GOOD LUCK, I HOPE TO HELP!

    
28.04.2017 / 02:00