3
$id = Yii::app()->user->getState("logId");
$name = Yii::app()->user->getState("username"); 

$dataProvider=Disnotification::model->findAllByAttributes(array('logID' => $id,'username'!=$name));

如何找到等于$id但不等于的记录$name

4

3 回答 3

3
$criteria = new CDbCriteria();
$criteria->compare('logID' , $id);
$criteria->addCondition('username != :username');
$criteria->params[ ':username' ] = $name;

$dataProvider = Disnotification::model()->findAll( $criteria );
于 2014-08-27T06:10:17.087 回答
3
$criteria=new CDbCriteria;
$criteria->condition = "username != '$name' AND logID = :id";
$criteria->params = array (
    ':id' => $id,
);
$dataProvider = Disnotification::model()->findAll( $criteria );
于 2014-08-27T09:28:43.923 回答
0
$dataProvider = Disnotification::model() -> findAllByAttributes(
        array(
            'logId'=>$id,
        ),
        new CDbCriteria(
            array(
                'order'=>'x ASC, y DESC',
                'condition'=>'username<>'.$username,
            ))
    );
于 2015-04-08T10:48:12.430 回答