php搜索中的mysql查询(仅邮政编码的第一部分)

php搜索中的mysql查询(仅邮政编码的第一部分),php,mysql,map,Php,Mysql,Map,我使用以下查询显示搜索栏中的结果 $query = "SELECT * FROM $usertable WHERE ($postcodelist LIKE '%$search%' OR $city LIKE '%$search%') AND $office <> '' GROUP BY $office"; $query= “从$usertable中选择*,其中 ($postcodelist,如“%$search%” 或$city(如“

我使用以下查询显示搜索栏中的结果

$query = 
"SELECT * FROM $usertable WHERE 
    ($postcodelist LIKE '%$search%' 
      OR $city LIKE '%$search%') 
    AND $office <> ''  
    GROUP BY $office";
$query=
“从$usertable中选择*,其中
($postcodelist,如“%$search%”
或$city(如“%$search%”)
及$office“
按$office分组”;
如果我输入LS19或利兹,它会显示利兹办公室的详细信息,因为我的邮政编码列表最多4位

但是,如果我搜索LS19 6BR(我的完整邮政编码),它不会显示任何内容,因为这与邮政编码列表根本不匹配

我需要以某种方式搜索用户输入的部分内容,然后输入邮政编码,但不需要搜索用户输入的城市

这可能吗


谢谢

因为你有一个搜索词来搜索两个字段,这很棘手。我会考虑把它分成2个搜索字段。然而,除非我同意:

$postcodesearch = substr($search,0,4);
$query = 
"SELECT * FROM $usertable WHERE 
   ($postcodelist LIKE '%$postcodesearch%' 
     OR $city LIKE '%$search%') 
   AND $office <> ''  
   GROUP BY $office";
$postcodesearch=substr($search,0,4);
$query=
“从$usertable中选择*,其中
($postcodelist类似“%$postcodesearch%”
或$city(如“%$search%”)
及$office“
按$office分组”;

将邮政编码搜索字段限制为4个字符?好主意。。。非常奥卡姆剃须刀!然而,搜索字段是城镇或邮政编码。我可以知道您该字段的数据类型吗?它们是
id
int(4)默认为空,
postcodelist
varchar(4)默认为空,
city
varchar(50)默认为空,
lat
decimal(4,2)默认为空,
lng
decimal(8,6)默认为空,
office
varchar(50)默认为空,
line1
varchar(50)默认为空,
line2
varchar(50)默认为空,
postcode
varchar(10)默认为空,
country
varchar(10)默认为空