Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含城市和邮政编码字段的搜索表单。搜索是查询 mysql 数据库并返回相关结果。
为了让用户更轻松,是否可以将这两者结合起来并允许在该字段中输入城市或邮政编码?
谢谢
它只是表示查询中的“或”子句,类似于:
SELECT ... WHERE city='$formfield' OR postcode='$formfield'
使用is_numeric()函数(或正则表达式)来确定您请求的数据类型(城市名称或邮政编码)。
is_numeric()
是的。城市名称可能不是以数字开头,因此请使用正则表达式进行过滤,并与正确的字段进行比较。