PHP MySQL search with multiple criteria

前端 未结 3 450
温柔的废话
温柔的废话 2021-01-23 15:04

I have a search form in a website and would like to have several search terms which is input by the user to perform db search, terms as below:

  • Keywords
  • Pr
3条回答
  •  盖世英雄少女心
    2021-01-23 15:26

    You're going to need parentheses.

    SELECT * FROM `project` WHERE (`proj_title` LIKE '%keywords%' OR `proj_addr` LIKE '%keywords%' OR `proj_area` LIKE '%keywords%') AND `proj_for`='Sale' AND `state`='Somewhere' AND `proj_cat`='8' AND `price` BETWEEN '250000' AND '600000'
    

    Without the parentheses it just has to match one of the criteria before the last OR.

提交回复
热议问题