YII中的不相等条件

8zzbczxx  于 2022-11-09  发布在  其他
关注(0)|答案(2)|浏览(256)

我需要根据employment_status = activeaccount_type != admin筛选下拉列表
下面是我代码:

<?php
$employeesList = array();
$employees = Employee::model()->findAllByAttributes(array('employment_status' => 'active', 'account_type' ??? 'admin'));
foreach ($employees as $employee) {
   $employeesList[$employee->company_id] = $employee->getName();
} 
?>

如何获得'account_type' != 'admin'
请帮帮忙。

hwazgwia

hwazgwia1#

有多种方法可实现此目的:

$employees = Employee::model()->findAllByAttributes(array('employment_status' => 'active'), 'account_type' != 'admin');

或者,

$criteria=new CDbCriteria;
$criteria->condition = "account_type != 'admin' AND employment_status = :status";
$criteria->params = array (
    ':status' => "active",
);
$employees = Employee::model()->findAll( $criteria );
zaqlnxep

zaqlnxep2#

在yii1中,下面的代码对我很有效。

$employees = Employee::model()->findAllByAttributes(array('employment_status' => 'active'), 'account_type <> "admin"');

相关问题