Addcondition In Search() Using >= Or <=

Hi everyone, I’ve been looking for a solution to use >= and <= in search(), I’ve found lots of workarounds about like and others…

But I need to add 2 conditions in order to filter a data in search() method, I’ve tried:




$criteria->compare('t.telefono',$this->telefono,true);

....


$criteria->addCondition('t.f1 >= :f1','AND');

$criteria->params[':f1']='1356994800'

$criteria->addSearchCondition('f2 <= :f2','AND');

$criteria->params[':f2']='1388444400';



But it doesn’t work…

In SQL it would be :




where ... and t.f1>=X and t.f2<=X



Does anyone know anything about this?

Thx!

Try the following: http://www.yiiframework.com/doc/api/1.1/CDbCriteria#addBetweenCondition-detail

Try that




…


$criteria->addCondition('t.f1 >= :f1'); // AND is the default anyway

$criteria->addCondition('f2 <= :f2');

$criteria->params = array(

    ':f1' => '1356994800', 

    ':f2' => '1388444400',

);


…


$criteria->compare('t.telefono',$this->telefono,true);



PS1 Generally, when you post that something doesn’t work, you should give more details

PS2 Is addSearchCondition in your original code a typo or on purpose?

THX!!!! it works! :D

How can I print the values that search() recieve?

Because I need to check something… I’ve tried with echo and other like using js alerts but I cant get the values…




$criteria->compare('t.email',$this->email,true);

		$criteria->compare('t.telefono',$this->telefono,true);

....




echo "<script type='text/javascript'>

alert('".$f1."');

console.log('".$f1."');

</script>";

echo $f1;


$criteria->addBetweenCondition('t.field',$f1,$f2,'AND');

		




How can I print them to check them????

Thx again!