problem, dependent dropdown list show only one record

Hi Everyone!

Excuseme for my bad english… :P

I have two dropdownlist, one dependent from other (i read tutorial from the wiki)

The first represent the code of state and the second represent the city of the specific state…but show only one city (the last of the table).

The two table are:




comuni(id ,codice_provincia,codice,nome)

province(id,codice_regione,codice,nome,sigla)



the part of interest of view is:




	<div class="row">

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

                <?php echo $form->dropDownList($model,'provincia', $città_data,array(

                                'ajax' => array(

                                'type'=>'POST',

                                'url'=>CController::createUrl('contatti/dynamiccities'),

                                'update'=>'#'.CHtml::activeId($model,'citta')

                             	)));


            ?>

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

	</div>


	<div class="row">

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

		<?php echo $form->dropDownList($model,'citta', array());?>

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

	</div>



the part of interest of controller is:




public function actionDynamiccities()

{


  $data=Comuni::model()->findAll('codice_provincia=:codice_provincia',array(':codice_provincia'=>1));

    $data=CHtml::listData($data,'codice_provincia','nome');

    foreach($data as $value=>$name)

    {

        echo CHtml::tag('option',

               	array('value'=>$value),CHtml::encode($name),true);

    }

}



the value 1 is there to lead the search without "problem"

The function have the authorization in the controller.

So…where is the problem?Why show only one record?

thanks in advance!!

P.s. the DB is correct and populated.

The code seems good… check the result of findall()… check the generated SQL and try to run it manually on your database…

I run it manually on database and works fine.(how can i check the generated SQL?)

However finally i find my mistake…


$data=CHtml::listData($data,'codice_provincia','nome');

The value codice_provincia is not unique, so the code generate only one row.

if i change codice_provincia with another value i have all record that correspond to the value codice_provincia.

But still i have i problem!I need codice_provincia for update a


$form->textField

…how can i do?

If that is not unique… than on the form you will have a dropdown with same values… which one will the user seelct?

Or even worse… the names are different and the user see all items different… but the value submitted can be duplicate…

the solution is in


$data=CHtml::listData($data,'codice','nome');

because codice is different for every record!

how to show value when update ???

Is there any possible way to show the duplicate values in a dropdownlist ?

I have a similar situation in which the values in a dropdownlist are same but the labels are different.

Is it possible ?

Thanks in advance :)