I am using this query to return search results
$id = $this->auth->get_user_id();
$query = $this->db->query("
SELECT user_id,
facebook_id,
first_name,
last_name,
country,
state,
city,
picture,
cars_id,
cars_name,
cars_picture
FROM user_profiles
JOIN users
ON users.id = user_id
JOIN cars
ON cars.id_fk = user_id
WHERE user_id NOT LIKE '$id'
AND activated = 1
AND banned = 0
AND first_name LIKE '%$search_term%'
OR last_name LIKE '%$search_term%'
OR Concat(first_name, ' ', last_name) LIKE
'%$search_term%'
ORDER BY last_name ASC;
");
If I click on an empty search box it return all users, if I put in a first name or last name it returns only that specific user as search result. Using command line, this query gives similar results when manually entering (or leaving blank) $id, $first_name, etc.
BUT, here's the strange behavior: the following lines seem to have no effect on the query:
user_id NOT LIKE '$id' //line 1
AND activated = 1
AND banned = 0
For example, I am not able to exclude the current user from search results (line 1).
No matter what I put in for activated or banned, clicking on a blank search always returns all users.
The kicker is that if I run this SQL on command line and manually enter
user_id NOT LIKE '5'
AND activated = 1
AND banned = 0
it filters the results correctly.
Does anyone know what I'm doing wrong? Thanks for helping!