How To Write Multiple Condition Togather?

hello friends…

here is my code…




public function actionIndex()

	{

	$model = new ProductIndex();

	$price = (isset($_GET['ProductIndex']['price'])) ? $_GET['ProductIndex']['price'] : array();

    CVarDumper::dump($price);

     $criteria = new CDbCriteria();

	 //take the other table column

	 $criteria->with = 'pricing';

	if ( isset($_GET['ProductIndex']['price']) && ($price[0] == 0 ))

	{

	$results = pricing::model()->findAll(array( 'condition'=>'price>=:price AND price <= :price1',

    'params'=>array(':price'=>0, ':price1'=>2000),

	));

	$values = array();

	foreach($results as $r) $values[] = $r->price;

	$criteria->addInCondition( 'pricing.price', $values ); 

	}

	if( isset($_GET['ProductIndex']['price']) && $price[0] == 1 )

	{

	$results = pricing::model()->findAll(array( 'condition'=>'price>=:price AND price <= :price1',

    'params'=>array(':price'=>2001, ':price1'=>5000),));

	$values = array();

	foreach($results as $r) $values[] = $r->price;

	$criteria->addInCondition( 'pricing.price', $values ); 

	}

	if( isset($_GET['ProductIndex']['price']) && $price[0] == 2 )

	{

	$results = pricing::model()->findAll(array( 'condition'=>'price>=:price AND price <= :price1',

    'params'=>array(':price'=>5001, ':price1'=>10000),));

	$values = array();

	foreach($results as $r) $values[] = $r->price;

	$criteria->addInCondition( 'pricing.price', $values ); 

	}

here i use 3 conditions and 3 query individual,and it work fine for the individual operation.

now i want to these condition work togather.

please suggest me to any method in which i will do it.

thanks.

anyone?

the qn is not clear!!

thanks Rajith…

i create here ajex search for the price.

here i pass the value from the module

here is my module code…


<?php

class ProductIndex extends CActiveRecord

{

const TYPE_LESS2000='0';

	const TYPE_2001to5000='1';

	const TYPE_5001to10000='2';

 public function getPriceOptions()

        {

            return array(

                self::TYPE_LESS2000=>'Below 2000',self::TYPE_2001to5000=>'2001 to 5000',

				self::TYPE_5001to10000=>'5001 to 10000',

                

            );

        }

}

in my view…




		<h4>Price Range:</h4>

		<?php

echo CHtml::activeCheckBoxList($model,'price',

$model->getPriceOptions(),	

array( 'template'=>'<li>{input} {label}</li>',  'class'=>'masterIndexFilter',)); 

		?>

<?php

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

 var ajaxUpdateTimeout;

    var ajaxRequest;

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

	 product_id = $('.masterindexFilter').serialize();

    $.fn.yiiListView.update(

        'ajaxListView',

                {

                 url: '" . CController::createUrl('productindex/index') . "',

                 data: product_id,

				}

    );

}); 

);

?>

in my controller…




  public function actionIndex()

	{

	$model = new ProductIndex();

	$price = (isset($_GET['ProductIndex']['price'])) ? $_GET['ProductIndex']['price'] : array();

    CVarDumper::dump($price);

     $criteria = new CDbCriteria();

	 //take the other table column

	 $criteria->with = 'pricing'; 

	 $criteria->together = true; 

	if ( isset($_GET['ProductIndex']['price']) && ($price[0] == 0 ))

	{

	$results = pricing::model()->findAll(array( 'condition'=>'price>=:price AND price <= :price1',

    'params'=>array(':price'=>0, ':price1'=>2000),

	));

	$values = array();

	foreach($results as $r) $values[] = $r->price;

	$criteria->addInCondition( 'pricing.price', $values ); 

	}

	if( isset($_GET['ProductIndex']['price']) && $price[0] == 1 )

	{

	$results = pricing::model()->findAll(array( 'condition'=>'price>=:price AND price <= :price1',

    'params'=>array(':price'=>2001, ':price1'=>5000),));

	$values = array();

	foreach($results as $r) $values[] = $r->price;

	$criteria->addInCondition( 'pricing.price', $values ); 

	}

	if( isset($_GET['ProductIndex']['price']) && $price[0] == 2 )

	{

	$results = pricing::model()->findAll(array( 'condition'=>'price>=:price AND price <= :price1',

    'params'=>array(':price'=>5001, ':price1'=>10000),));

	$values = array();

	foreach($results as $r) $values[] = $r->price;

	$criteria->addInCondition( 'pricing.price', $values ); 

	}

	$dataProvider = new CActiveDataProvider('ProductIndex',

	array('criteria'=>$criteria));

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

            'dataProvider'=>$dataProvider,

			'model'=>$model,

            ));

			}

in actionIndex. i write the condition for search the price range from the price column.here i write 3 separate condition for the search the data from the price column.here only one checkbox work at a time.

now, i want to write all this condition in one condition and search all together.

then how to work all checkbox together?

for example if i check 2 checkbox then it search 2 range and display both check value.such as 3.

Hi,

This example will help you,


$uid=Yii::app()->user->id;

$sql="SELECT DISTINCT `id_project` FROM task WHERE username='$uid'";                        

$projects=Task::model()->findAllBySql($sql);

     

$ids=array();   

foreach($projects as $project):        

    $ids[]=$project->id_project;

endforeach;


$criteria= new CDbCriteria;

$criteria->addInCondition('id_project', $ids);

$criteria->order='task_end ASC';

$criteria->offset=0;

$criteria->limit=10;

Are you looking for CDbCriteria::mergeWith?

http://www.yiiframework.com/doc/api/1.1/CDbCriteria#mergeWith-detail