search option

i have 2 tables in db. i want to search and display the details. how i will display the details… i don’t no my code is right or not… give me some suggestions. here my code is…


$criteria = new CDbCriteria();				//create new object for search function

		

		if(isset($_GET['q']))								//if value of search is set

		{

			$q = $_GET['q'];								//assign search box value to variable

			//var_dump($q);exit;

			//var_dump($criteria->compare('user_name', $q, true, 'OR'));exit;

			$criteria->compare('id', $q, true);					//compare model attributes to search value

			$criteria->compare('user_name', $q, true);			//compare model attributes to search value

		}

		

		$model=new CActiveDataProvider("StudentTbl", array('criteria'=>$criteria));					//load the model 

		//var_dump($model);exit;


		$this->render('index',array(

		'model'=>$model,

		));

Are U planing to use this for CGridView or something similar

use grid view and advanced search

you can use gridview here help yourself

http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/

tnx for reply