+----+-------------------+----------+--------------+
| id | address | city | state |
+----+-------------------+----------+--------------+
| 1 | 13000 highway 244 | keystone | south dakota |
+----+-------------------+----------+--------------+
(顺便说一句,我遗漏了一些专栏以便更容易)
$string = mysql_real_escape_string('13000 highway 244 south dakota');
$a = mysql_query("
SELECT * FROM `table` WHERE
CONCAT_WS(' ', `address`, `city`, `state`) LIKE '%$string%'
");
上述搜索查询不会返回任何结果,只有以下values
才能生效:
但是,我还想让以下values
工作:
是否可以在不依赖full-text search
?
答案 0 :(得分:1)
为什么不这样更明确地编码?
$address = mysql_real_escape_string('13000 highway 244');
$city = mysql_real_escape_string('keystone');
$state = mysql_real_escape_string('south dakota');
$a = mysql_query( '
SELECT *
FROM `table`
WHERE ( ( address = ' . $address . ' )
AND ( city = ' . $city . ' )
AND ( state = ' . $state . ' )
)
OR ( state = ' . $state . ' )
.. probably more alternatives ...
');
答案 1 :(得分:0)
用通配符替换空格,所以即使“130 dakoda”也可以工作
$string = str_replace( array('*', '?', ' '), array('%', '_', '%'), $string); //Change norm wildcards to mysql format and replace spaces with wildcards