Yii Framework Forum: multiply search conditions - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

multiply search conditions Rate Topic: -----

#1 User is offline   jnosul 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 07-July 10

Posted 08 July 2010 - 12:08 AM

Hi, I have a beginner question about multiply search conditions. I need to do something like:

select .... where( condition1 AND( condition2 OR condition3 or condition4 ) );
we can say, that condition5 = condition2 or condition3 or condition4;

so its all about: select... where( condition1 AND condition5 );

How should I do it along with yii filosophy? In symfony criteria we had criterion objects for such operations.

thanks in advance :rolleyes:
1

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 08 July 2010 - 01:30 AM

In Yii you have CDbCriteria - http://www.yiiframew...api/CDbCriteria
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   jnosul 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 07-July 10

Posted 08 July 2010 - 02:06 AM

View Postmdomba, on 08 July 2010 - 01:30 AM, said:

In Yii you have CDbCriteria - http://www.yiiframew...api/CDbCriteria


iknow, that we have CDbCriteria. i was trying to solve my problems in many ways, e.g using addSearchCondition. but did you read my question? How can I prepare one composite condition chained with OR and add it into the main condition with AND?
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 08 July 2010 - 02:37 AM

in the simplest form you can use


$cr=new CDbCriteria();
$cr->condition= '( condition1 AND( condition2 OR condition3 or condition4 ) )';


Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   jnosul 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 07-July 10

Posted 08 July 2010 - 04:03 AM

View Postmdomba, on 08 July 2010 - 02:37 AM, said:

in the simplest form you can use


$cr=new CDbCriteria();
$cr->condition= '( condition1 AND( condition2 OR condition3 or condition4 ) )';




thanks. And can we use addSearchCondition for instance? If yes, how to do it?
condition1-4 are the type of sql %name% LIKE ones, so I thought using addSearchCondition is the best way. If not, which one is?

This is my third project in Yii, and this time I want to use only its best features, and write the code as much as possible along with the framework philosophy.

again, thanks for ur time, Jan
0

#6 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 08 July 2010 - 04:19 AM

I don't know what you Ć¾ink by "best way"...

For elegant written code there are the addCondition/addSearchCondition

Iif you check the source you will see that addSearchCondition call addCondition, and addCondition sets the condition property... so for the speed (a micromilisecond :) ) just set the condition property...

I realy don't know how to get your need with addSearchCondition in other way than

$cr=new CDbCriteria();
$cr->addSearchCondition('condition1'...);
$cr->addSearchCondition('condition2 or condition3 or condition4',...);

Find more about me.... btw. Do you know your WAN IP?
0

#7 User is offline   jnosul 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 07-July 10

Posted 08 July 2010 - 05:08 AM

Are these both two equal?


1)
$cr=new CDbCriteria();
$cr->addSearchCondition('condition1'...);
$cr->addSearchCondition('condition2 or condition3 or condition4',...);


2)

$cr=new CDbCriteria();
$cr->condition= '( condition1 AND( condition2 OR condition3 or condition4 ) )';


Obviously there is no AND in the first one. Can we do something like in the second example for addSearchCondition ?

$cr=new CDbCriteria();
$cr->addSearchCondition('condition1 AND ( condition3 or condition4 )',...);

0

#8 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 08 July 2010 - 05:47 AM

Ops... addSearchCondition cannot be used that way, take a look at the doc - http://www.yiiframew...ondition-detail

my example works with addCondition()

so if you use only one addCondition('big expresion')... it's the same as writing $cr->condition='big condition'
Find more about me.... btw. Do you know your WAN IP?
0

#9 User is offline   jnosul 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 07-July 10

Posted 08 July 2010 - 08:18 AM

Thanks for your time. The rest I will figure out by myself :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users