Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Cdbcriteria With Addbetweencondition

$
0
0
In my database I store a value. Then in the search I have two fields and I need to find all the records where that value is between the two fields.

The code for the form is
 <div class="row">
                <div class="checkBoxMed">
                    <?php echo $form->checkbox($model,'percentRecycledContent', array('id'=>'checkBoxMed3', 'name' => 'percentRecycledContent_check')); ?>
                    <label for="checkBoxMed3"></label>
                </div>
                <?php echo $form->labelEx($model,'percentRecycledContent', array('label'=>'Recycled content between', 'style'=>"width:165px;")); ?>
                <div class="percentWrapper">
                    <?php echo $form->textField($model, 'percentRecycledContent[start]', array('class'=>'percentInput')); ?>
                    <label for="and">and</label>

                    <?php echo $form->textField($model, 'percentRecycledContent[end]', array('class'=>'percentInput')); ?>
                    <span>%</span>
                    
                </div>
            </div>

The code search in the model is
 public function search() {
		$criteria = new CDbCriteria;
                $criteria->with = array( 'company', 'category' );
                
		$criteria->compare('company.name', $this->company_name, true);
		$criteria->compare('t.Name', $this->Name, true);
		$criteria->compare('category.name', $this->category_name, true);
		$criteria->addBetweenCondition('percentRecycledContent', $this->percent_start, $this->percent_finish, true);
		$criteria->compare('Description', $this->Name, true);
		$criteria->compare('otherInformation', $this->Name, true);
		$criteria->compare('Materials', $this->Name, true);

		return new CActiveDataProvider($this, array(
			'criteria' => $criteria,
                        'sort'=>array(
                            'attributes'=>array(
                                'company_name'=>array(
                                    'asc'=>'company.name',
                                    'desc'=>'company.name DESC',
                                ),
                                'category_name'=>array(
                                    'asc'=>'category.name',
                                    'desc'=>'category.name DESC',
                                ),
                                'Name',
                                'percentRecycledContent',
                            ),
                        ),
                        'pagination'=>array(
                                'pageSize'=> Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']),
                        ),
		));
	}


I also have this in the model
        public $company_name;
        public $category_name;
        public $percent_start;
        public $percent_finish;


I get an SQL error, the focus is - percentRecycledContent BETWEEN NULL AND NULL

How can I get this working?

Thank you

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>