Small question about the LIKE operator. I’m trying to implement a very basic search system and it “works” in that it returns the record I want but it’s also returning some records that don’t appear to match the search query at all and while I don’t have many records to test with, it appears to be returning 5 each time out of 8 total and the same few each time PLUS the actual result I;m expecting.
SELECT * FROM comments WHERE status = '0' OR status='1' AND (author LIKE '%test%' OR author_email LIKE '%test%' OR author_url LIKE '%test%' OR ip LIKE '%test%' OR comment_body LIKE '%test%') ORDER BY comment_id
This is my query as it is processed, obviously with ‘test’ replaced with whatever the query is at the time.
The highlighted is the result I expected when searching for ‘test’.
Same here while searching for ‘Fisher’
I thought somehow it was combining their IP’s as the repeat offenders share one, but there is a 6th record with the same IP which is not returned so that doesn’t seem to be it.
Am I utilizing this query wrong?
EDIT: I think I’ve found part of the problem, the extra ones being returned are all set to “Status = 0”. Setting one of them to status = 1 removed it.
EDIT2; Figured it out, was returning all with Status 0 AND ones with Status = 1 and meeting the search requirements. Added some brackets to the "WHERE (status) section and it seems to be fixed.