How Can I Write Search Condition Using Criteria

i have select one column from the table.

in my index page i have add two search field such as

3569

product.PNG

i want to both the search field active at a time and search the column elements.

so, what i condition put in cdbcriteria in model or controller ?

please suggest me…

thanks

in controller :


public function actionIndex()

	{

	$criteria=new CDbCriteria;

	


	$dataProvider=new CActiveDataProvider('ProductIndex',array('criteria'=>array('select'=>'product_name',

					'condition'=>array('where'=>array('and','product_name=micromax100','product_name=lalala')))

					));

	$model = new ProductIndex('search');

    $model->unsetAttributes();

	if(isset($_GET['q']))

		$model->product_name = $_GET['q'];	

			 $model->save();

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

			'dataProvider'=>$model->search()

			));

	}

in index.php




//this adds a javascript event listener to the search box that will query the server with each keystroke. yw0 is the id of the clistview. q is the id of the text input box:

Yii::app()->clientScript->registerScript('search', "

  $('input#q').keyup(function(){

  $.fn.yiiListView.update('yw0', {

  data: $(this).serialize()

  });

  return false;

});

");


?>


<h1>Product Indexes</h1>


<!-- add a search box: -->

<input type="textfield" id="q" name="q" value="mxn100" />

<input type="text" id="q" name="q" value="lalala" />

<?php $this->widget('zii.widgets.CListView', array(

'dataProvider'=>$dataProvider,

'itemView'=>'_view',

)); ?>

in model:


	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('index',$this->index);

		$criteria->compare('product_name',$this->product_name,true);

	        $criteria->compare('product_id',$this->product_id,true);

		$criteria->compare('image_index',$this->image_index,true);

		$criteria->compare('master_key',$this->master_key);

		$ProductIndex=ProductIndex::model()->findAll($criteria);

		

		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

			

					));

	

	}

please suggest me what condition put in this code for the working of the both search field together?

please anyone give me some suggestion…

thanks

I am not sure if this what you looking for


public function actionIndex()

        {

        $criteria=new CDbCriteria;

        


        $dataProvider=new CActiveDataProvider('ProductIndex',array('criteria'=>array('select'=>'product_name',

                                        'condition'=>array('where'=>array('and','product_name=micromax100','product_name=lalala')))

                                        ));

        $model = new ProductIndex('search');

    $model->unsetAttributes();

        if(isset($_GET['q']))

                $model->product_name = $_GET['q'];      

                         $model->save();

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

                        'dataProvider'=>$model->search()

                        ));

        }

change it as following


public function actionIndex()

        {

       $criteria=new CDbCriteria;

 $criteria->select="product_name";

 $criteria->addInCondition('product_name',array('lalala', 'micromax100')); 


 $dataProvider=new CActiveDataProvider('ProductIndex',array(

 	'criteria'=>$criteria

 ));

        $model = new ProductIndex('search');

    $model->unsetAttributes();

        if(isset($_GET['q']))

                $model->product_name = $_GET['q'];      

                         $model->save();

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

                        'dataProvider'=>$model->search()

                        ));

        }