title: Group by user, location and date range in YII Framework
body: <p>Can someone help me on how to use the date range (create_date) and grouping the data by user_id and location?</p>
  
  <p>I input the field user_id, location and daterange, sorting results just happened to date range.
  I tried many times to fix the controller, but the outcome remains the same.</p>
  
  <p>If I just input the the user_id field and input the location and no date range field sorting on CGridView only by user_id and the location, date range remains in random order.</p>
  
  <p>Below is a model,controller and view</p>
  
  <p><strong>Model</strong>
  <strong>my variable in model</strong>  </p>
  
  <pre><code> public $from_date;
   public $to_date;
        ....
   public function search()
          {
              $criteria=new CDbCriteria;
  
  
              $criteria-&gt;compare('user_id',$this-&gt;user_id);
              $criteria-&gt;compare('location',$this-&gt;location,true);
              $criteria-&gt;compare('satisfy_val',$this-&gt;satisfy_val,true);
              $criteria-&gt;compare('create_date',$this-&gt;create_date,true);
              /* $criteria-&gt;mergeWith($this-&gt;dateRangeSearchCriteria('create_date',$this-&gt;create_date
              )); */
              if(!empty($this-&gt;from_date) &amp;&amp; empty($this-&gt;to_date)){
                  $criteria-&gt;condition="create_date &gt;= '$this-&gt;from_date'";
              }elseif(!empty($this-&gt;to_date) &amp;&amp; empty($this-&gt;from_date)){
                  $criteria-&gt;condition="create_date &lt;= '$this-&gt;to_date'";
              }elseif(!empty($this-&gt;to_date) &amp;&amp; !empty($this-&gt;from_date)){
                  $criteria-&gt;condition="create_date &gt;= '$this-&gt;from_date' and create_date&lt;= '$this-&gt;to_date'";
              }
  
              return new CActiveDataProvider($this, array(
                  'criteria'=&gt;$criteria,
                  'sort'=&gt;array('defaultOrder'=&gt;array('user_id DESC','create_date DESC')),
              ));
          }
  </code></pre>
  
  <p><strong>This is my controller</strong></p>
  
  <pre><code>public function actionAdmin()
      {
          $model=new Satisfact('search');
          /* $model-&gt;unsetAttributes();  // clear any default values */
          if(isset($_GET['Satisfact'])){
              /* $model-&gt;attributes=$_GET['Satisfact']; */
              $model-&gt;user_id=$_GET['Satisfact']['user_id'];
              $model-&gt;lokasi=$_GET['Satisfact']['location'];          
              $model-&gt;from_date=$_GET['Satisfact']['from_date'];
              $model-&gt;to_date=$_GET['Satisfact']['to_date'];
  
          }
              $this-&gt;render('admin',array(
              'model'=&gt;$model,
          ));
  
  
      }
  ...............
  </code></pre>
  
  <p><strong>and my view</strong></p>
  
  <pre><code>&lt;div class="wide form"&gt;
  
  &lt;?php $form=$this-&gt;beginWidget('CActiveForm', array(
      'action'=&gt;Yii::app()-&gt;createUrl($this-&gt;route),
      'method'=&gt;'get',
  )); ?&gt;
  
  
  
      &lt;div class="row"&gt;
          &lt;?php //echo $form-&gt;label($model,'user_id'); ?&gt;
          &lt;?php //echo $form-&gt;textField($model,'user_id'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'user_id'); ?&gt;
          &lt;?php $_u = User::model()-&gt;findAll();
                    echo CHtml::activeDropDownList(
                          $model,'user_id',
                          CHtml::listData($_u,'id','username'),
                          array('prompt'=&gt;'',) //empty is aliases FOR ALL user
                      );
                 ?&gt;
      &lt;/div&gt;
      &lt;div="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'location'); ?&gt;
          &lt;?php $lo_u = Location::model('Location')-&gt;findAll('id');
                    echo CHtml::activeDropDownList(
                          $model,'location',
                          CHtml::listData($lo_u,'location','location'),
                          array('prompt'=&gt;'',)
                      );
                 ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php //echo $form-&gt;label($model,'location'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="column"&gt;
          &lt;?php echo $form-&gt;label($model,'create_date'); ?&gt;
          &lt;?php //echo $form-&gt;textField($model,'create_date'); ?&gt;
          &lt;?php 
          echo "From : ";
              $this-&gt;widget('zii.widgets.jui.CJuiDatePicker',
              array(
              'name'=&gt;'Satisfact[from_date]',
              'options'=&gt;array('dateFormat'=&gt;'yy-mm-dd',),            
  
              ));
          echo " To : ";
              $this-&gt;widget('zii.widgets.jui.CJuiDatePicker',
              array(
              'name'=&gt;'Satisfact[to_date]',
              'options'=&gt;array('dateFormat'=&gt;'yy-mm-dd',),            
  
              )); 
  
  
          ?&gt;
      &lt;/div&gt;
  
      &lt;div class="column"&gt;
          &lt;?php echo CHtml::submitButton('Search'); ?&gt;
      &lt;/div&gt;
  
  &lt;?php $this-&gt;endWidget(); ?&gt;
  </code></pre>