MYSQL在同一列中多次

I have filter with 3 dropdown lists, each list contains same criteria (operator, service, SIM card). When these dropdown lists contain diferent search categories, search function is working fine, but if categories is the same in 2 or 3 dropdown lists, filter doesnt work correctly. Because of incorrect SQL query:

"SELECT * FROM table WHERE id = " . $_GET['id'] . " AND operator like %tele% AND operator like %bite%"

should be

"SELECT * FROM table WHERE id = " . $_GET['id'] . " AND operator like %tele% OR operator like %bite%"

This is my php code for filter:

 $this->_sql['where'].= $this->reg['post']['flt_find_1'] ? " AND ".$this->reg['post']['flt_field_1']." like '%".$this->reg['post']['flt_find_1']."%' " : "";      
 $this->_sql['where'].= $this->reg['post']['flt_find_2'] ? " AND ".$this->reg['post']['flt_field_2']." like '%".$this->reg['post']['flt_find_2']."%' " : "";  
 $this->_sql['where'].= $this->reg['post']['flt_find_3'] ? " AND ".$this->reg['post']['flt_field_3']." like '%".$this->reg['post']['flt_find_3']."%' " : "";  

How to check if all categories in the filter are different, then use AND for each, but then categories are the same, to use OR (or maybe there is other way to solve that).

Thanks.

  1. Your code is vulnerable to sql-injections, so check the get parameter;
  2. If I understand you correctly, try it like this:
SELECT * FROM table WHERE id = '".($_GET['id']*1)."' AND ( operator LIKE '%tele%' AND operator LIKE '%bite%' )";