How To Work With Findall


$user=Users::model()->findAll('status=:status',array(':status'=>5));

using above code I need to get the


$user->email;

but it will give error

"Trying to get property of non-object "

can you tell me how do I get it;

in my model I have status and email attribute.I need get the all the email from the table where status =5

how do I get it pls help me.

That’s because findAll() returna ARRAY of values, not a single value.

Use find() if you want to get only one record.




$user=Users::model()->findAll('status=:status',array(':status'=>5));

foreach($user as $user_1)

{

echo $user_1->email;

}




Try this…

can you tell me how do I get all the record not only one.

whaen it

echo $user_1->email it also display only one record.how do I get all the record of email column.pls help me

according to your condition in find all there is only one record is present , If you want all record remove the condition in the findAll()

can you pls post the code for that.when remove the condition it will give the error

http://www.yiiframework.com/doc/guide/1.1/en/database.ar




$user=Users::model()->findAll();

foreach($user as $user_1)

{

echo $user_1->email;

}




Actually, you had a typo.

Should be


echo $user_1->email;

thanx