Working With Sql In Yii

Hai Everyone,

I have a scenario where i have to get the values from some table.

I used findbysql() to get all the values.




$result = Mymodel::model()->findAllBySql("SELECT * FROM `something` WHERE `IID` IN (:iids) and `Duration` < 24 and `RegID` = :regid and `GCID` = :gcid",array( ':iids'=>$value1 , ':regid' => $value2, ':gcid'=>$value3));



and my variable holding the values such




$value1 = 2,3;

$value2 = 2,

$value3 = 5,



everything works cool as i expected. Except for one thing. when the $value1 is replaced in :iids it should check for both the values like 2 or 3. But the query always executed for the first value.

i.e

when the $value1 is 2,3 am getting the results only to 2 not for 3 then, if the $value1 is 3,4 then i am getting the results only to 3 not for 4.

(Sorry for my English)

I Don’t know whats wrong in this.

Please help me with this.

Thanks in advance.

-Paapi

[size=2]try $value1 as array and then send[/size]

Thanks for the reply,

I have tried that too like,




$values = explode(",", $value1);



Its always returns an empty array to me.

even I have tried with criteria too




                                $criteria = new CDbCriteria;

				if($_POST['checklist']!=1)

				   $criteria->addInCondition('IID',$values);

				

				$criteria->addCondition('some < 24');

				$criteria->addCondition('some2 = :ex');

				$criteria->addCondition('some3= :gcid');


				$criteria->params = array('ex' => $value2, 'gcid' => $value3);


				$results = Mymodel::model()->findAll($criteria);



That too returns the same result.

Is there anything wrong?

Can you show the exact code you’ve used to split the values into an array.

This isn’t going to do what you expect:




$value1 = 2,3;



so, unless that’s a typo, it’s probably the cause of the problem.

The values need to be in a string if you’re going to explode them:




$value1 = "2,3";



Also, stick with the CDbCriteria version; I don’t think PDO will bind an array in that way.

Thanks for the reply,

I don’t thing explode cause the problem. Because when i was trying to print the $values(explode’s return array) using print_r()

I got the result as




 Array ( [0] => 4 [1] => 5 [2] => 6 [3] => 7 )



then only i was tried to get the result using




    $criteria->addInCondition('IID',$values);



Is there anything i did wrong? Please let me know

Thanks in advance

paapi