Get the last saved value to the dropdown from the database on update

531 Views Asked by At

I would like to update my database content and I first need to check the last saved value to my user and allow him to update his data !!!

here is my code but it doesn't work !!!

$form->dropDownList($persons,'sex', array(''=>"Choose" ,'M'=>'Man', 'F'=>'Woman'), array('options' => array($person_data['sex'] => array('selected'=>true))));

print_r($person_data['sex']) is showing me the right value from DB ('M' or 'F').

can any one show me how to do this please. i already check here but most of solution propose just show with a particular index but it's not working for me.

2

There are 2 best solutions below

1
On

Bellow code will help you

   <?php
   echo $form->dropDownList($YorModel,'sex', array('M'=>'Man', 'F'=>'Woman'),array('empty'=>'----Select Gender-----'));
   ?>
0
On

Will this work?In the options array,

array('options' => array($YourModel->attribute =>  array('selected' => true)))

Just a Guess!!