v20agarwal
(Varunagarwal Ep)
1
hi …
i have a drop down list and i use the fuction to findall() to find all the company names is the database .
what i want to do is show only the company’s with status=1
please help in what do i change to do so . how to use condition with findall() function …
thanks a lot .
abennouna
(Abennouna)
2
Hello,
Yii API doc and the forum’s search feature are your friends
http://www.yiiframework.com/doc/api/1.1/CActiveRecord#findAll-detail
Now, your answer in the case of an CActiveForm:
echo $form->dropDownList($model, 'countryId',
CHtml::listData(Company::model()->findAll(array('condition' => 'status = :status', 'params' => array(':status' => 1))), 'id', 'name'),
array('empty' => 'Please select a company »')
);
or
echo $form->dropDownList($model, 'countryId',
CHtml::listData(Company::model()->findAll('status = 1'), 'id', 'name'),
array('empty' => 'Please select a company »')
);
(you can also see here: http://www.yiiframework.com/doc/api/1.1/CActiveForm#dropDownList-detail)
redguy
(Maciej Lizewski)
3
…or
Company::model()->findAllByAttributes( array( 'status'=>1 ) )
abennouna
(Abennouna)
4
Company::model()->findAll('status = 1')
is shorter
abennouna
(Abennouna)
5
By the way this shouldn’t even be in bug discussions