DropDownList Data Retrival From Multiple Table

i m new to yii and and for my project i made dropdownlist after lots of effort i made it…

Here is a code of data retrieval from multiple table

view code…




<?php Yii::app()->clientScript->registerCoreScript("jquery")?>

<script type="text/javascript">

jQuery(function($){

$('select').change(function(){

var id=$(this).val();

var child=$(this).attr('child');

var parent=$(this).attr('id');

$.ajax({

type:'post',

url:"load",

data:{id:id,child:child,parent:parent},

dataType: 'json',

cache: false,

success: function(data) {

var out;															

$(data).each(function(){out+="<option value="+this.id+">"+this.name+"</option>";

});

$('#'+child).append(out);

}

});

});

});

</script>


<div class="form">

	<?php $uni = University::model()->findAll(); ?>

	<div id="row">

		<?php echo CHtml::label('University',''); ?>

		<?php echo CHtml::dropDownList('university','',CHtml::listData($uni,'id','name'),

						array('prompt'=>'Select University',

							'child'=>'deptt'

						)

		); ?>

	</div>

	<div id="row">

		<?php echo CHtml::label('Department',''); ?>

		<?php echo CHtml::dropDownList('deptt','',array(),

			array('prompt'=>'Select Department',

				'child'=>'stream'

			)

		); ?>

	</div>

	

	<div id="row">

		<?php echo CHtml::label('Stream',''); ?>

		<?php echo CHtml::dropDownList('stream','',array(),

						array('prompt'=>'Select Stream',

							'child'=>'batch'

						)

		); ?>

	</div>

	

	<div id="row">

		<?php echo CHtml::label('Batch',''); ?>

		<?php echo CHtml::dropDownList('batch','',array(),

						array('prompt'=>'Select Stream',

							'child'=>'not'

						)

		); ?>

	</div>

</div><!-- form -->




controller code…





public function actionload()

	    {

				$table=$_POST['child'];

				$id = $_POST['id'];

				$parent = $_POST['parent'];

				$sql = "SELECT id,name FROM tbl_{$table} WHERE {$parent}_id={$id}";

				$data=Yii::app()->db->createCommand($sql)->queryAll();

				echo CJSON::encode($data);				

	}



and i attach database file

2494

dump.sql.zip

enjoy

Sorry for my poor english

in this example

i take value parameter as id ,

current table name as parent and

next table name as child