【发布时间】:2013-03-13 14:03:49
【问题描述】:
我有 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(或者可能有其他解决方法)。
谢谢。
【问题讨论】:
-
"SELECT * FROM table WHERE id = " . $_GET . " AND operator like %tele% OR operator like %bite%"- 你为什么要连接一个字符串和一个数组? -
@Sann 我弄错了,我已经编辑了我的问题。
-
你没有消毒。停在那里,重新思考你在做什么。
-
@Hiroto 我知道,我只是为这个问题写的,这不是我要的,谢谢。
-
请也出示您的html代码。