fire
(Fire)
1
Hi there,
I’ve seen many tutorial sites that expalin how to use model()->find with one parameter as a value. but what about two?
Ie:
I want to find all users with first name Paul, and last name Smith
[size=2]
[/size]
[size=2]how do I do this?[/size]
[size=2]
[/size]
[size=2]
[/size]
[size=2]Please help![/size]
samdark
(Alexander Makarov)
2
$criteria = new CDbCriteria();
$criteria->compare('first_name', 'Paul');
$criteria->compare('last_name', 'Smith');
$users = User::model()->findAll($criteria);
mikl
(Mike)
3
Alternative:
User::model()->findAll('first_name=? AND last_name=?', array('Paul', 'Smith'));
andy_s
(Arekandrei)
4
Another alternative:
User::model()->findAllByAttributes(array('first_name'=>'Paul', 'last_name'=>'Smith'));
http://www.yiiframework.com/doc/api/CActiveRecord#findAllByAttributes-detail
teuku
(Teuku Milist)
5
what kind of output that will shown using all of those method?
mine shows not only the data i want it to be.
dckurushin
(Diavolonok)
6
it will return you set of models
added that to common questions
http://www.yiiframework.com/wiki/258/common-yii-questions/#hh9