MySQL
+----+-------------------+----------+--------------+
| id | address | city | state |
+----+-------------------+----------+--------------+
| 1 | 13000 highway 244 | keystone | south dakota |
+----+-------------------+----------+--------------+(顺便说一句,我漏掉了一些专栏,这样就更容易了)
PHP
$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才能工作:
南达科他州keystone
但是,我还想让下面的values开始工作:
南达科他州keystone
在不依赖full-text search的情况下,这可能吗?
发布于 2012-02-17 23:58:08
为什么不像这样更明确地编码呢?
$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 ...
');发布于 2013-07-31 09:47:14
在传递查询字符串之前,用通配符替换空格,这样即使是"130达科达“也能工作。
$string = str_replace( array('*', '?', ' '), array('%', '_', '%'), $string); //Change norm wildcards to mysql format and replace spaces with wildcards
https://stackoverflow.com/questions/9336909
复制相似问题