Compare question in yii

Almost every wiki explains simple things. I am stuck in yii problem CDbcriteria.

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

select * from users where status ='active'

This comparison is explained:

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

But I can not find an example script that describes it using operator-based search. Like not for the following query:

select * from users where status !='active'

How can i do this?

+5
source share
4 answers

try something like this

$criteria->condition = " status<>'active'";
$criteria->compare('status',$this->status,true);
+5
source

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

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

+4
source

Try

$criteria->addCondition("NOT status = 'active'");
+1
source

I had the following 3 conditions and it works like a charm:

$criteria->condition='employee_id<>:employee_id AND vehicle_id=:vehicle_id AND checked_in_on IS NULL';
            $criteria->params=array(':employee_id'=>Yii::app()->session['activity']->employee_id,':vehicle_id'=>$model->id);
            $checkedOutVehicleBySomeoneElse = Activity::model()->find($criteria);
+1
source

All Articles