Shilpa Kirad
Shilpa Kirad

Reputation: 219

In yii application How to insert data which is fetched from another table into current table

I have two tables in database namely QbQuestion(Qid,Question,StatusId) and Qbstatus(StatusId,Status),,,,,where Status stores status as new,acive,inactive etc. i want to fetch StatusOptions on view form of QbQuestion in form of dropdownBox. i got succeded to fetch StatusOptions on QbQuestion view form but that selected entry is not getting inserted in QbQuestion table. In _form.php,to fetch StatusOptions, i have inserted code as follows: labelEx(Qbstatus::model(),'Status'); ?> findAll(); $list = CHtml::listData($records,'QuestionStatusId', 'Status'); echo CHtml::dropDownList('Qbstatus', null, $list, array('empty' => 'Select a Status')); ?> error(QbStatus::model(),'Status'); ?>

So what i should do in order to make entries in QbQuestion table

Upvotes: 0

Views: 978

Answers (1)

Brett Gregson
Brett Gregson

Reputation: 5913

Your question is not very clear, but from what I understand you are unable to make the drop down list display the correct options/values, which then prevents your QbQuestion table from storing the correct id for the QuestionStatusId?

Here is how your drop down list should look (untested obviously):

echo CHtml::dropDownList($model,'StatusId',CHtml::listData(Qbstatus::model()->findAll(),'QuestionStatusId','Status'),array('empty'=>'Select a Status'));

If you view the source you should see a normal HTML structure with Display Value

In your controller/action that receives the form, you should be able to echo out the model value for the StatusId and see there if it is getting passed

Upvotes: 0

Related Questions