William de Castro
William de Castro

Reputation: 86

MYSQL, how to search keyword in multiple columns?

How can I search a keyword in multiple columns in mysql syntax?

Now I have a variable $phone, that store the form input, and use the syntax to search in a single column:

SELECT * FROM db.table WHERE 'phone1' = '".$phone."';

How I make that search through columns 'phone1', 'phone2', 'phone3' and 'phone4'?

Thanks

Upvotes: 0

Views: 1084

Answers (2)

bonCodigo
bonCodigo

Reputation: 14361

Why not try in: =)

SELECT * 
FROM db.table 
WHERE '".$phone."' in (`phone1`, `phone3`, `phone3`, `phone4`)
;

Upvotes: 1

John Conde
John Conde

Reputation: 219894

Use OR in your WHERE clause

SELECT * 
FROM db.table 
WHERE 'phone1' = '".$phone."'
OR 'phone2' = '".$phone."'
OR 'phone3' = '".$phone."'
OR 'phone4' = '".$phone."'

Upvotes: 5

Related Questions