Problem With Cdbcriteria Condition

I’m having a problem with the condition of cdbCriteria.

It doesn’t seem to work. In the condition, I state that “country_id=2”, but the results that I print out does not show country_id=2. Instead, the results show a combination of various country_id (those that equals to 2 as well as those not equals to 2).

My code is as below. Is there anything wrong?

Controller codes:




$criteria->select = 't.*, user.*, country.*';

$criteria->join = ' INNER JOIN user ON t.user_id = user.id INNER JOIN country ON t.country_id = country.country_id';

$criteria->condition = 't.country_id=2'; //this does not work. It does not return results whereby country_id=2


$dataProvider=new CActiveDataProvider("Project", array('criteria'=>$criteria));




Take a look at resulting query in YII’s info logs.

Sorry… I’m relatively new to Yii.

But how do I check the resulting query in Yii’s info logs? Where is it located?

You can activate CWebLogRoute in your configuration file. See Logging on the guide for details.

try to use $criteria->compare(‘t.country_id’, 2);

if you use $criteria->coundition more than 1 times, Only last condition will work.

I think you gave not all code. Becouse now, your code is correct

Use $criteria->compare(‘t.country_id’, 2);

or $criteria->addCondition(‘t.country_id = 2’);

Tks everyone! :)

I didn’t state any other conditions within my codes. I tried using this but I don’t know why it can’t work:

$criteria->addCondition(‘t.country_id = 2’);

But it’s ok since I managed to get what I need using this:

$criteria->compare(‘t.country_id’, 2);