MySql SELECT names from users WHERE name LIKE “$searchTerm” AND status <> ‘blocked’

mysqlselectsqlweb-applications

I need to make a Query like this.

MySql-> SELECT names from users_tb WHERE names LIKE "$searchTerm" AND status <> 'blocked'

So The Query should SELECT all ROWS with names that match the "Search term", but Skip ROWS where "status='blocked'". Now the issue is that Once the Like '%$searchTerm%' is called, the Query returns even those users that are 'blocked'. In other words, the AND is completely ignored.

How could this be properly done?

Any Help is highly appreciated.

Best Solution

I suppose the Query could run without warning or error, as you didn't mention that. So the problem is logically.

Please try

"SELECT names from users_tb WHERE names LIKE "$searchTerm" AND status = 'blocked'"

IF it comes out the result of name match to searchTerm AND status = blocked,

The SQL

"SELECT names from users_tb WHERE names LIKE "$searchTerm" AND status <> 'blocked'" should work for name match to searchTerm AND status NOT EQUALS TO blocked.

If it still doesn't. would you mind looking into your db records see if they are correct.