使用MySQL SELECT语句搜索记录

时间:2012-06-01 13:56:17

标签: php mysql search

我正在尝试在数据库中搜索用户输入的字词。这是我正在使用的MYSQL语句:

SELECT CompanyName, FirstName, LastName, Phone, Email, City, Rep, id 
FROM calls 
WHERE Rep='JSC' && CompanyName || FirstName || LastName || PhoneMisc1 || Email || City LIKE '%$terms%'

问题是,它不仅返回Rep ='JSC'的记录,而且其余部分用于返回类似术语的列。

1 个答案:

答案 0 :(得分:0)

喜欢

SELECT CompanyName, FirstName, LastName, Phone, Email, City, Rep, id  
FROM calls WHERE Rep='JSC' and 
(
CompanyName LIKE '%$terms%' 
or
FirstName LIKE '%$terms%' 
 or 
 LastName LIKE '%$terms%' 
or 
PhoneMisc1 LIKE '%$terms%' 
or 
Email LIKE '%$terms%' 
or 
City LIKE '%$terms%'
)