Using not equal operator in Cakephp
27,375
Solution 1
As @Josh suggested, try using NOT IN. The correct format for CakePHP 1.3.x is:
$this->User->find('all', array(
'conditions' => array(
'NOT' => array(
'User.id' => array(1, 2, 3)
)
)
));
Taken from http://cakebaker.42dh.com/2007/04/26/how-to-use-not-in-in-a-condition/
Solution 2
$this->paginate(
'Article',
array (
'Article.status <>' => 'Inactive',
'Article.user_id !=' => $blocked_ids,
'Article.tags LIKE' => "%" . trim($this->params['url']['tag']) . "%"
)
);
Solution 3
This should be handled when you're getting your data in your model function. You should exclude them by using code like this:
'conditions' => array(
'Article.status' => 'active',
Author by
Josh Randall
Updated on July 30, 2020Comments
-
Josh Randall over 3 years
I have find query that looks like this.
$this->paginate('Article', array('Article.status !=' => 'Inactive', 'Article.user_id !=' => $blocked_ids, 'Article.tags LIKE' => "%" . trim($this->params['url']['tag']) . "%"))
where $blocked_ids is an array of ids. It throws an error
SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= ('170')
When I removed
!=
it works fine. No ErrorsI appreciate any help.