在mysql列中选择包含字符串的行

时间:2015-02-04 15:11:19

标签: php mysql

我正在尝试在列$places中选择包含字符串ADDRESS的所有行。这是我编码的内容,但它只适用于单元格只包含该字符串的情况,如果有其他字符则不起作用

$sql = "SELECT *,CONCAT(mapLan,',',mapLon) as LatitudeLongitude FROM " . $table . " where ADDRESS like '$places' and SIZE between $firstrange and $secondrange";

例如$places = "East London" 它只会选择一个单元格只存储East London的行,而只留下Old Street, East London

的单元格

我想要的是选择列East London中包含ADDRESS的所有行

1 个答案:

答案 0 :(得分:3)

您忘记使用通配符。

<强>含义:
匹配任意数量的字符,即使是零字符

$sql = "SELECT *,CONCAT(mapLan,',',mapLon) as LatitudeLongitude FROM " . $table . " where ADDRESS like '%$places%' and SIZE between $firstrange and $secondrange";

visit this link for detail