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


Select a row containing a string in a mysql column

我正在尝试选择列ADDRESS中包含字符串$places的所有行。 这是我编码的内容,但它仅在单元格仅包含该字符串时才有效,如果有其他字符,它将无法正常工作

$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 LondonADDRESS的行

您忘记使用 % 通配符。

意义:
% 匹配任意数量的字符,甚至零个字符

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

访问此链接了解详细信息