【发布时间】:2013-07-01 22:42:29
【问题描述】:
我有一个数据字符串,我从中剥离了一些单词,然后将其放入一个数组中以放入查询中。
这些词似乎可以很好地剥离,但 like 语句仍然会在它们所在的位置找到并插入一个空白搜索。这是在退缩一切,这是不好的。
我不太确定为什么会这样。我看起来不像是在单词之间添加了额外的空格,我已经尝试打印出数组,但没有任何效果,所以我很茫然。
这是我的 str_replace
$str = str_replace(array('and', 'this', 'that', 'or', 'boo', 'wound', 'but'), '', $userPost);
然后我在空间中爆炸以将其变成一个数组
$words = explode(' ', $str);
然后在 foreach 中我正在做我喜欢的声明
$this->db->or_where("`terms` LIKE '%$word%'");
查询是这样出来的
SELECT * FROM (`filter_tbl`) WHERE `terms` LIKE '%real%' OR `terms` LIKE '%%' OR `terms` LIKE '%blank%' OR `terms` LIKE '%%' OR `terms` LIKE '%%' OR `terms` LIKE '%%' OR `terms` LIKE '%%' OR `terms` LIKE '%I%' OR `terms` LIKE '%love%' OR `terms` LIKE '%%' OR `terms` LIKE '%ty%' OR `terms` LIKE '%lets%' OR `terms` LIKE '%see%' OR `terms` LIKE '%if%' OR `terms` LIKE '%%' OR `terms` LIKE '%goes%' OR `terms` LIKE '%through%' OR `terms` LIKE '%please%' OR `terms` LIKE '%gg%' OR `terms` LIKE '%through%' OR `terms` LIKE '%%' OR `terms` LIKE '%%' OR `terms` LIKE '%%'
我知道这可能是我缺少的一些简单的东西,但我就是看不到它。感谢您的帮助!
【问题讨论】:
-
改用全文搜索
-
我用的是全文,只是想省略一些不必要的词
-
那么你的查询是错误的。
-
我的查询工作正常,我只是想省略一些要搜索的单词,因为它来自文本区域。
-
您的查询对于全文类型搜索不正确
.. MATCH (XX) AGAINST ...dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
标签: php sql codeigniter str-replace