i have tbl_score, here the structure :
id | nim | n_att | n_exercise | n_exam |
with my calculation so at CGridView , i’m add one column again (called Final Score Column)
after that i’m also want to add one column again (called Letter Column) the value of this column come from other table (tbl_lett) which have relation with Final Score Column. for the example : if the result of Final Score Column = 95 then at the Letter Column will show ‘A’.
here the structure of tbl_lett :
n_final_score (PK) | letter |
here the model of score:
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('nim',$this->nim);
$criteria->compare('n_att',$this->n_att,true);
$criteria->compare('n_exercise',$this->n_exercise,true);
$criteria->compare('n_exam',$this->n_exam,true);
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
}
public static function getLetter()
{
$n_value=0;
$provider = Score::model()->findAll();
foreach($provider as $data)
{
$n_final_score = floor(($data->n_att*0.1)+($data->n_exercise*0.2)+
($data->n_exam*0.3));
$sql = "SELECT `letter` FROM tbl_lett WHERE `n_final_score` like ':n_final_score%' ";
$n_value=Letter::model()->findBySql($sql,array(':n_final_score'=>$n_final_score));
}
return $n_b;
}
here the view :
...
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'score-grid',
'dataProvider'=>$model->search(),
//filter'=>$model,
'columns'=>array(
array(
'header'=>'Final Score',
'value'=>'floor(($data->n_att*0.1)+($data->n_exercise*0.2)+($data->n_exam*0.3))',
),
array(
'header'=>'Letter',
'value'=>'$data->Letter',
),
The result -> at the last column (Letter Column) was blank/ no display the value
Can someone help me, thanks