-4

我有 3 个下拉列表的过滤器,每个列表都包含相同的条件(运营商、服务、SIM 卡)。当这些下拉列表包含不同的搜索类别时,搜索功能可以正常工作,但如果 2 或 3 个下拉列表中的类别相同,则过滤器无法正常工作。由于不正确的 SQL 查询:

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

应该

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

这是我的过滤器 php 代码:

 $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']."%' " : "";  

如何检查过滤器中的所有类别是否不同,然后AND用于每个类别,但类别相同,使用OR(或者可能有其他方法来解决)。

谢谢。

4

1 回答 1

0
  1. 您的代码容易受到 sql-injections 的攻击,因此请检查 get 参数;
  2. 如果我理解正确,请尝试如下:
SELECT * FROM table WHERE id = '".($_GET['id']*1)."' AND ( operator LIKE '%tele%' AND operator LIKE '%bite%' )";
于 2013-03-13T14:20:19.390 回答