I’m working on a group management system and I’m trying to fine tune the search function so it searches more table fields with a single query.
I want it to search 2 fields, something like this:
[code=php]$query = “SELECT * FROM groups WHERE name LIKE ‘%$search%’ OR description LIKE ‘%$search%’ ORDER BY name”;
Of course that works fine. But here’s the part I’m having trouble with:
I need the query to only return results for groups that this user is allowed access to (based upon a membership_id). So I need something in there such as:
[code=php]$query = “SELECT * FROM groups WHERE name LIKE ‘%$search%’ OR description LIKE ‘%$search%’ AND membership_id = $id ORDER BY name”;
Problem is the last part with the membership_id gets ignored if either of the first two parts of the query are true.
I know it can be done with 2 queries, but is it possible to keep it all in one? Thanks in advance ?
BTW, it needs to be able to work on mySQL 4 too, if possible.