Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare issue in yii

Tags:

yii

In almost in every wiki simple things are explained. I'm stuck in yii's CDbcriteria compare issue.

Only the exact "equal to" match is explained for:

select * from users where status ='active'

This comparison is explained:

$criteria->compare('status','active');

But I can't find an example script which describes it with an operator based search. Like not equal to for the following query:

select * from users where status !='active'

How can I do this?

like image 945
Shahid Karimi Avatar asked Jan 16 '12 11:01

Shahid Karimi


3 Answers

try some thing like this

$criteria->condition = " status<>'active'";
$criteria->compare('status',$this->status,true);
like image 81
jayanthan Avatar answered Nov 04 '22 21:11

jayanthan


$criteria->addNotInCondition('status', array('active'));

if count(array('active')) === 1 sql will status != 'active', else status NOT IN ('active', 'smth else')

like image 41
cetver Avatar answered Nov 04 '22 21:11

cetver


Try

$criteria->addCondition("NOT status = 'active'");
like image 41
Gadelkareem Avatar answered Nov 04 '22 22:11

Gadelkareem