Please Help Dependent Dropdown

i need working code of 4 dependent dropdown list i read article of dependent dropdown lists but no luck someone please help me …this become my headache from last two weeks :(

The link below maybe helpful:

http://www.yiiframework.com/wiki/24/creating-a-dependent-dropdown/

Put your code for more help…

ok i show my code error become Invalid argument supplied for foreach()




My view code is

<?php

  $state = new CDbCriteria;

          $state->order = 'name ASC';

    

	 

	 echo $form->dropDownList($model,'name',CHtml::listData(Month::model()->findAll($state),'name','name'),

                    array(

                        'ajax' => array(

                        'type' => 'POST',

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

                        'update' => '#unionname'

                    )   

                )

          );

    

     echo $form->error($model,'name');?>

<?php

<div class="row">


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

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

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



My controller code is


public function actionDynamicstates()

{

  $sql = "SELECT name FROM Month ".

         "WHERE union = :union";

  $command = Yii::app()->createCommand($sql);

  $command->bindValue(':union', $_POST['union'], PDO::PARAM_INT);

  $data = $command->query();


  $data = CHtml::listData($data,'id','name');

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

  {

    echo CHtml::tag('option',

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

  }

}

Edit your code as below:




echo $form->dropDownList($model, 'state_id', array(1 => 'Tehran', 2 => 'Tabriz', 3 => 'Kh Razavi'), array(

	'ajax' => array(

    	'type' => 'POST', //request type

    	'url' => Yii::app()->createUrl('currentController/dynamiccities'), //url to call.

    	'update' => '#city_id', //selector to update

    	'data'=>array('state_id'=>'js:this.value'),//data sent via POST

    	)));



i also do like this but error comes through your code error is Missing argument 2 for CHtml::listData() And from my code is invalid argument supplied for foreach my code is like where error come


state = new CDbCriteria;

      $state->order = 'name ASC';

echo $form->dropDownList($model,'name',CHtml::listData(Month::model()->findAll($state),'name','name'),

 array(

                        'ajax' => array(

                        'type' => 'POST',

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

                        'update' => '#unionname'

                    )