Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a single value in findbyPk() method in yii?

Tags:

yii

In my controller

$agent = University::model()->findByPK($university_id);

I hope it will return value of a row of value. I want a single attribute(field3) value say university_name, (with out using findByPK), how to get it

SELECT  field3 FROM table [WHERE Clause]
like image 459
raghul Avatar asked Dec 01 '22 03:12

raghul


1 Answers

Try this

$usercriteria = new CDbCriteria();
$usercriteria->select = "university_name";
$usercriteria->condition = "university_id=$university_id";
$university = University::model()->findAll($usercriteria);

echo $university->university_name;

Or simply do like u did first

$agent = University::model()->findByPK($university_id);
echo $agent-> university_name;
like image 109
Ninad Avatar answered Dec 10 '22 23:12

Ninad