Sql Query Or Cdbcriteria

Hi guys. Need help on how can I show the classification of the user currently logged in using maybe SQL query or CDbCriteria. I have table with user_id and classification. If the user logged in I want to view the classification the user belonging to.

Example.

User_id | Classification

85 class I

85 class II

82 class I

81 class III

If I logged in with user_id = 85, how can I view only my classification?

I haven’t try using SQL command in view. Hope someone will help me here. Thank you.

Add a static method ‘getUserClassification’ to a model/helperclass/usermodel …





public static function getUserClassification($userId=null)

{

   if($userId === null)

      $userId = Yii::app()->user->id;


   $sql='SELECT Classification FROM classification WHERE user_id=:id';

   $command = Yii::app()->db->createCommand($sql);

   $command->bindParam(":id", $userId, PDO::PARAM_INT);

   

   return $command->queryAll(); 

}