-1

I want to create a search engine and I'm having some problems. This is my code:

SELECT COUNT(*) as num FROM `offerta` WHERE `text` LIKE '%".$sea."%' AND `regione`='$re'

Now it works. I want to search on several columns and filter results by category (regione).

SELECT COUNT(*) as num FROM `offerta` WHERE `titolo` LIKE '%".$sea."%' OR `text` LIKE '%".$sea."%' OR `nome` LIKE '%".$sea."%' AND `regione`='$re'

regione = '$re' is the category.

I want to use WHERE titolo LIKE '%".$sea."%' OR text LIKE '%".$sea."%' OR nome LIKE '%".$sea."%' AND regione='$re'

It works well until AND. When i use one time OR and AND, it works, but when i uses several time OR and AND it doesn't works.

I tried MATCH and AGAINST but same error keeps coming up.

  • possible duplicate http://stackoverflow.com/questions/2514548/how-to-search-multiple-columns-in-mysql – Sam Dec 03 '13 at 19:46
  • @Sam - The answer for that question is not the same as this scenario. – madebydavid Dec 04 '13 at 10:41
  • @user3062975 - do you get an error when you run that code? Or is it returning the wrong data? Please give us a little more information so that we can assist you. – madebydavid Dec 04 '13 at 10:42
  • madebydavid - It works well until AND. When i use one time OR and AND, it works, but when i uses several time OR and AND it doesn't works. – user3062975 Dec 04 '13 at 12:25

1 Answers1

1

I solved my problem:

SELECT COUNT(*) as num FROM offerta WHERE regione='$re' AND (titolo LIKE '%".$sea."%' OR text LIKE '%".$sea."%' OR nome LIKE '%".$sea."%')

Now it works well.