I'm going to write a search engine function for my content display script but I had some questions about how best to deal with structiong the WHERE clause of the SQL. I've looked online but this is typically a slightly hard core for most people so there is nothing that I have found that covers this in terms of SQL.
Take for example the following search string:
"test this" +foo -bar otherwise
What this should do is return records that:
1. contains "test this" (%test this%)
2. contains 'foo'(AND '%foo%')
3. OR contain 'otherwise' (OR '%otherwise%')
4. NOT contain 'bar' (<> '%bar%')
Anyways, short of writing a small WHERE clause novel, is there a way that I can nest the WHERE statements so that it appears like:
Where `field` like '%test this%' (AND '%foo%' (OR '%otherwise%' (<> '%bar%')))
This is just a un-educated guess but you should be able to see where I'm trying to go with this. What is the best way to structure a WHERE clause of this nature?
TIA
Sean Shrum
Take for example the following search string:
"test this" +foo -bar otherwise
What this should do is return records that:
1. contains "test this" (%test this%)
2. contains 'foo'(AND '%foo%')
3. OR contain 'otherwise' (OR '%otherwise%')
4. NOT contain 'bar' (<> '%bar%')
Anyways, short of writing a small WHERE clause novel, is there a way that I can nest the WHERE statements so that it appears like:
Where `field` like '%test this%' (AND '%foo%' (OR '%otherwise%' (<> '%bar%')))
This is just a un-educated guess but you should be able to see where I'm trying to go with this. What is the best way to structure a WHERE clause of this nature?
TIA
Sean Shrum