0

I have a SELECT with a WHERE clause:

WHERE (`city` LIKE '%".$search."%' )

$search is passed from a search box.

I'm trying to make it fit the search in 2 or even 3 tables. Something like:

WHERE (`name`, `country`, `city` LIKE '%".$search."%' )

Using that I get error:

Operand should contain 1 column(s)

What is wrong there? Also I would appreciate a hint about how could I make it search in concatenated tables? I mean for a search like David Chicago.

potashin
  • 44,205
  • 11
  • 83
  • 107
SilenceIsGolden
  • 59
  • 1
  • 1
  • 6

2 Answers2

3
WHERE (`name` LIKE '%".$search."%' OR `country` LIKE '%".$search."%' OR `city` LIKE '%".$search."%' )
Kohjah Breese
  • 4,008
  • 6
  • 32
  • 48
  • Worked like a charm! Thank you. Now, if you are still here, can you give me a hint or something about how could I make it search in concatenated tables? For example, for a querry like `David Chicago` to get all Davdis from Chicago. – SilenceIsGolden Jun 03 '14 at 20:56
0
 WHERE `name` LIKE '%".$search."%' 
   OR `country` LIKE '%".$search."%'
   OR `city` LIKE '%".$search."%'
potashin
  • 44,205
  • 11
  • 83
  • 107
  • 8
    That might match Mr Mexico, living in Mexico City, Mexico, but would fail almost every other search. I think you mean `OR`. –  Jun 03 '14 at 20:49
  • I will try it right now, but do you have a reason to use `AND` and not `OR`? – SilenceIsGolden Jun 03 '14 at 20:49
  • 1
    @SilenceIsGolden : Yes, of course you should use `OR`. I was concentrated on improving the `WHERE` clause with multiple `LIKE` and I have not noticed the assignment of this query. – potashin Jun 03 '14 at 21:05