Why doesnt this work?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

Why doesnt this work?

Post by dominod »

Hi !

I am trying this code:

Code: Select all

 $query = "SELECT * FROM `table` WHERE name LIKE '%$keyword%' AND blocked != '%no%' ORDER BY hits DESC LIMIT 10 ";
The 'blocked' row has the following value: "se dk no uk es"

Now, what I want it to do is to NOT include that row IF it finds "no" in the blocked row... The problem is that it dont block it :/ It works if I dont use wildcard characters and the 'blocked' row = 'no' but I want to have multiple values in that row...


Thanks in advance :)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Why doesnt this work?

Post by AbraCadaver »

% is used as a wildcard in LIKE expressions:

[text]AND blocked NOT LIKE '%no%'[/text]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

Re: Why doesnt this work?

Post by dominod »

Thanks alot! U made my day :D
Post Reply