我有3個下拉列表過濾器,每個列表包含相同的標準(運營商,服務,SIM卡)。當這些下拉列表包含不同的搜索類別時,搜索功能工作正常,但如果類別在2或3個下拉列表中相同,則過濾器無法正常工作。因爲不正確的SQL查詢:MYSQL LIKE在同一列多次
"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表WHERE ID =」。 $ _GET。 「AND運算符像%tele%OR運算符如%bite%」' - 爲什麼要連接一個字符串和一個數組? – ShuklaSannidhya 2013-03-13 14:06:56
@Sann我犯了一個錯誤,我編輯了我的問題。 – DEJU88 2013-03-13 14:08:57
你不是在消毒。在那裏停下來,重新思考你在做什麼。 – Amelia 2013-03-13 14:09:49