[SOLVED] Problems with IN condition...

Hello again,

I have the following data in a table called Details

[table]

[tr]

[td]id[/td][td]idAccount[/td][td]Text[/td]

[/tr]

[tr]

[td]1[/td][td]1[/td][td]AAA[/td]

[/tr]

[tr]

[td]2[/td][td]1[/td][td]BBB[/td]

[/tr]

[tr]

[td]3[/td][td]1[/td][td]CCC[/td]

[/tr]

[tr]

[td]4[/td][td]1[/td][td]DDD[/td]

[/tr]

[tr]

[td]5[/td][td]2[/td][td]EEE[/td]

[/tr]

[tr]

[td]6[/td][td]2[/td][td]FFF[/td]

[/tr]

[/table]

And I have the followind code in my controller:



$indexes = array(1,3)





$inCondition=Details::model()->dbConnection->commandBuilder->createInCondition(Details::model()->tableName(), 'id', $indexes);


	$criteria = new CDbCriteria;


	$criteria->condition = '(( idAccount = :idAccount ) AND ( NOT :inCondition ))';


	$criteria->params = array(':idAccount'=>1,':inCondition'=>$inCondition);





	$details = Details::model()->findAll($criteria);


But $detalis has all the details with idAccount = 1, but I want only those details with idAccount = 1 and NOT IN (1,3)

What I expect is the details whose ids are 2 and 4…

Hope I explain myself…

Well, any suggestion?

I'm using yii 1.1 and mysql…

I add



Yii::trace('-------------------------------');


$details = Details::model()->findAll($criteria);


Yii::trace('-------------------------------');


To rapidly fetch the trace in the application.log…

The result:



2009/05/12 16:01:51 [trace] [application] ----------------------------------------


2009/05/12 16:01:51 [trace] [system.db.ar.CActiveRecord] DetalleDiario.findAll()


2009/05/12 16:01:51 [trace] [system.db.CDbCommand] Querying SQL: SELECT * FROM `Details` WHERE (( id = :idDiario ) AND ( NOT :inCondition ))


2009/05/12 16:01:51 [trace] [application] ----------------------------------------


Nobody can help me with that?

I don't you can bind :inCondition this way. Since $inCondition is already escaped properly (by createInCondition), you can directly insert it into your SQL.

Ahhh… OK, perfect, works perfect now! Thanks!