Accessing Values Gained From The Databse

Hi,

I’m obtaining a set of values from the database. I want to access attributes which were queried from the database… (classId and the admsiionId of each row). I tried using a loop but can’t figure out how to do it…




public function actionAdmin(){

$date= "SELECT DATE(now())";

$mydate = Yii::app()->db->createCommand($date)->queryScalar();


$count="select classId,admissionId from studentattendances where Date=$mydate";

$resultset=array();

$resultset=Yii::app()->db->createCommand($count)->query();


}




Please help me.

Thank you! :)

Hi @Nilu


public function actionAdmin(){

$date= "SELECT DATE(now())";

$mydate = Yii::app()->db->createCommand($date)->queryScalar();


$count="select classId,admissionId from studentattendances where Date=$mydate";

//$resultset=array(); //you do not really need thισ, the below query return the appropriate data structure

$resultset=Yii::app()->db->createCommand($count)->query();


echo $resultset['classId'];

echo '<br/>';

echo $resultset['admsiionId'];

}

Notes:

You must strongly avoid to settle a parameter, directly in query, there are way to do that with yii

The query method returns only the first record so if you want all of them results you have to use queryAll() method

If you want some help about that, please tell us :)

Thank u this worked for me! :)