How To Create A Drop Down List


I have two tables student,and student group. In student table there has student group_id, which is foreign key of Student group table. Now i want a list where group name will be drop down and ASC order.

In the _form page of student folder write code

<div class="row">

<?php echo $form->labelEx($model,'Group_ID'); ?>

<?php echo $form->dropDownList($model,'StudentGroup', CHtml::listData(StudentGroup::model()->findAll(), 'Group_Id', 'Group_Name'), array('empty'=>'Select location'));?>

<?php echo $form->error($model,'Group_ID'); ?>


It shows the following error

Property "student.studentGroup" is not defined.

how to solve this.

Please help me as soon as possible.

In dropdown you have,take studentgroup as a second parameter,why?

There is no field name with name studentgroup,in student model,so it is obvous error.

You should take Group_ID,& also change ‘empty’=>‘select group’ ::)

This way,it will work.

Try like this

<?php echo $form->dropDownList($model,'article', RefArticleEquipment::getArticle()); ?>

public static function getArticle(){

    $prov1 = RefSupply::model()->findAll();

    $data1 = CHtml::listData($prov1, 'id', 'article_code');

    $prov2 = RefEquipment::model()->findAll();             

    $data2 = CHtml::listData($prov2, 'id', 'article_code');

    return array_merge($data1, $data2); 


this may help for your solution

How to create two drop down lists which will have relationship with each other, like selecting a category from a drop down lsit should populate corresponding brands in second drop down. Thnaks in advance

Hi, Please go through this.