[英]Select a row containing a string in a mysql column
I am trying to select all rows which contains string $places
in a colum ADDRESS
. 我试图在列
ADDRESS
选择包含字符串$places
所有行。 here is what I coded but it only works when a cell only contains that string if there is other characters it wouldn't work 这是我编码的内容,但它只适用于单元格只包含该字符串的情况,如果有其他字符则不起作用
$sql = "SELECT *,CONCAT(mapLan,',',mapLon) as LatitudeLongitude FROM " . $table . " where ADDRESS like '$places' and SIZE between $firstrange and $secondrange";
For example $places = "East London"
It would only select the row in which a cell only store East London
and would leave alone the cells with Old Street, East London
例如
$places = "East London"
它只会选择一个单元格只存储East London
的行,并且将单独留下Old Street, East London
的单元格
What I want is to select all those rows which contains East London
in Column ADDRESS
我想要的是在列
ADDRESS
选择包含East London
所有行
You forget to use the % wildcard. 你忘了使用%通配符。
meaning: 含义:
% Matches any number of characters, even zero characters % 匹配任意数量的字符,甚至零个字符
$sql = "SELECT *,CONCAT(mapLan,',',mapLon) as LatitudeLongitude FROM " . $table . " where ADDRESS like '%$places%' and SIZE between $firstrange and $secondrange";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.