How to leave search field prepared to search for any term

1

I have a register of textures where the code of the same is composed of numbers and sometimes with letters, for example:

Código: 2564
Código: C-6551

I would like to leave the search field ready to search for any term searched by the user, such as:

User search for code 6551 the search return C-6551, I tried to do a search using REPLACE but it did not work very well, what I did was:

SELECT *
  FROM cor_textura
 WHERE REPLACE(REPLACE(REPLACE(codigo, '.', ''), '-', ''), ' ', '') =
       REPLACE(REPLACE(REPLACE('".$edBusca."', '.', ''), '-', ''), ' ', '')
   AND cor_textura.status = 1

I tried to substitute the term search by changing ponto by espaço , traço by espaço and espaço by espaço .

The database I'm using is phpMyAdmin and the table structure is this:

'cor_textura' (
  'id_cor_textura' int(10) NOT NULL AUTO_INCREMENT,
  'codigo' varchar(150) NOT NULL,
  'img' int(10) NOT NULL,
  'status' tinyint(5) NOT NULL,
  PRIMARY KEY ('id_cor_textura')
)

As I said, I could not solve my problem.

    
asked by anonymous 07.03.2016 / 13:12

1 answer

1

If you use the command LIKE of which you search anywhere in the text?

SELECT *
  FROM cor_textura
 WHERE codigo like '%6651%'
   AND cor_textura.status = 1

I made a example in SQLFindle , using MySQL, see if that would be it.

O obtained return:

| id | codigo | status |
|----|--------|--------|
|  3 | C-6551 |      1 |
    
07.03.2016 / 13:16