phpdev
phpdev

Reputation: 511

insert sql result inside array in yii 1

I need execute following sql in yii 1 application.

select user_group.user_id and user_rights.region_id 
from user_rights inner join user_group on
 user_rights.user_group_id=user_group.user_group_id

and to retrieve only all region_ids and paste it inside array? (e.g

                $regions = array();
                $regions[]='1';
                $regions[]='2';

) How can I do it using foreach(or another way) in yii 1?

Upvotes: 1

Views: 85

Answers (1)

Kumar Rakesh
Kumar Rakesh

Reputation: 2708

Try with this query: you will get all region_id . You can use as your wish by foreach loop etc.

 Yii::app()->db->createCommand()
    ->select('user_rights.region_id')
    ->from('user_rights')
    ->join('user_group', 'user_rights.user_group_id=user_group.user_group_id')
    ->queryAll();

Also for creating query in Yii please read more here: DOCs

Upvotes: 1

Related Questions