Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>The Main reason.</strong></p> <p>In your database table column(user_city_id), you have <strong>Empty values</strong> not <strong>NULL values</strong>. So your query is unable to operate "IS NULL" and "IS NOT NULL" on the corresponding column.</p> <pre><code> 1. NULL is Special Data Type. 2. Where as Empty means a string/value which is empty. </code></pre> <p>You can read more <a href="https://stackoverflow.com/questions/5615747/what-is-the-difference-between-null-and-empty">here</a></p> <p><strong>No need to add operator for first addCondition</strong></p> <p>For your information, When you are adding a condition to your criteria, no need to add "AND" operator becoz by default "AND" is the operator in <a href="https://github.com/yiisoft/yii/blob/1.1.14/framework/db/schema/CDbCriteria.php#L218" rel="nofollow noreferrer">addConditon</a>. And no use if you add operation for first addCondition, You should add this for your next addConditions if you have any. </p> <pre><code> //AND is not required here as AND is default operation. //This operator (AND) wont help in first condition. $criteria-&gt;addCondition('condition1=1','AND'); //This bellow condition will be concatenate with above condition so, here operator is required. $criteria-&gt;addCondition('condition2=1','OR'); </code></pre> <p><strong>The Solution is</strong></p> <p>I dont like to disturb default search method in my model. <strong>As i'm using MVC Framework, i should follow at least some MVC rules. Otherwise there is no meaning using this MVC.</strong> So, accessing $_GET stuff in my Model is not good here. so i'm creating a new method in my Model with two parameters.</p> <pre><code> function yourModelMethod($isParamExist,$customer_basics_id) { $criteria = new CDbCriteria; $criteria-&gt;condition = "customer_basics_id=$customer_basics_id"; if($isParamExist) { $criteria-&gt;condition='TRIM(user_city_id) =""'; } else { $criteria-&gt;condition='TRIM(return_date) !=""'; } return new CActiveDataProvider($this, array( 'criteria' =&gt; $criteria, )); } </code></pre> <p>Now, I'm using this model method from my controller</p> <pre><code> function actionYourController() { $model=new MyModel(); $isParamExist=isset($_GET['ulip']); $customer_basics_id=CustomerBasics::getCustomerBasicsId(Yii::app()-&gt;session['user_id']); $activeData=$model-&gt;yourModelMethod($isParamExist,$customer_basics_id); $this-&gt;render('myView',array('activeData'=&gt;$activeData)); } </code></pre> <p>I hope, it will definitely solve your problem. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload