php/mysql搜索多个值 [英] php/mysql search for multiple values

查看:74
本文介绍了php/mysql搜索多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有(国家,城市,区域,已发布)字段的表房.我有一个搜索表,有人可以输入国家,城市或地区.我想获取所有已发布的房屋= 1,并且任何搜索词都与它们的任何字段匹配.

I have a table homes with (country,city,area,published) fields. I have a search form where someone can enter country or city or area. I want to get all homes which are published = 1 and any of the search terms matches any of their fields.

这是我到目前为止所拥有的:

This is what I have so far:

SELECT * FROM homes 
WHERE published = 1 
AND 
LOWER(country) LIKE '$search%' 
OR 
LOWER(city) LIKE '$search%'
OR
LOWER(area) LIKE '$search%'

问题是它返回的房屋已发布= 0 ...

The problem is that it return homes that have published = 0...

推荐答案

我建议使用括号.

SELECT * FROM homes 
WHERE published = 1 
AND
(
 LOWER(country) LIKE '$search%' 
 OR 
 LOWER(city) LIKE '$search%'
 OR
 LOWER(area) LIKE '$search%'
)

这篇关于php/mysql搜索多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆