我有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
(或者可能有其他方法来解决这个问题)
感谢。
答案 0 :(得分:0)
SELECT * FROM table WHERE id = '".($_GET['id']*1)."' AND ( operator LIKE '%tele%' AND operator LIKE '%bite%' )";