Guest User

Untitled

a guest
Feb 12th, 2018
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. $criteria = new CDbCriteria;
  2. $criteria->select = 't.first_name, t.email'; // select fields which you want in output
  3. $criteria->condition = 't.status = 1';
  4.  
  5. $data = Users::model()->findAll($criteria);
  6.  
  7. User::find()->select(['field1', 'field2']);
  8.  
  9. $active_users_emails = User::model()->findColumn('email', 'active = 1');
  10.  
  11. **returns array('rajat@gmail.com','rajatsinghal@gmail.com')..**
  12.  
  13. $active_users_emails=CHtml::listData(User::model()->findAllByAttributes(array('active'=>1)), 'id', 'email');
  14.  
  15. $criteria = new CDbCriteria;
  16. $criteria->select = 't.first_name, t.email'; // select fields which you want in output
  17. $criteria->condition = 't.status = 1';
  18.  
  19. $data = Users::model()->findAll($criteria);
  20.  
  21. foreach($data as $model){
  22. $rows[] = array_filter($model->attributes);
  23. }
  24.  
  25. echo CJSON::encode($rows)
  26.  
  27. [{"first_name" : "Rohit", "email" : "rohitsuthar@gmail.com"}, {"first_name" : "Rajat", "email" : "rajat@example.com"}]
  28.  
  29. $emailIds = Yii::app()->db->createCommand(
  30. 'SELECT email FROM users WHERE is_active = 1'
  31. )->queryAll();
  32.  
  33. $emailIds = array_column( $emailIds, 'email' ) );
Add Comment
Please, Sign In to add comment