Hi,
if you want a statement like
A OR (B AND C AND D)
you can do this:
$conditions = array(
'OR' =>
array(
A,
array(B, C, D)
)
);
Read: Apply operator OR to the following arguments A plus
array(B,C,D). The second argument to the OR operator expands further
to an AND statement (AND operator with 3 arguments B,C,D).
Note that the AND for B, C, D is implicit. So you could also write:
$conditions = array(
'OR' =>
array(
A,
array(
'AND' =>
array(B, C, D)
)
)
);
You may want to take another look at the manual here
http://manual.cakephp.org/chapter/models
regarding complex find conditions.
The idea behind this is to supply conditions in polish / prefix
notation where the operator precedes the arguments, to facilitate tree-
like representation.
http://en.wikipedia.org/wiki/Polish_notation
Best,
jp
On 30 Jan., 05:43, brandags <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I'm trying to generate a query with the following condition:
>
> WHERE Lead.user_id = $user_id
> OR (Lead.time_found BETWEEN '$start_time' AND '$end_time' AND
> Lead.user_id IN ('0',NULL))
>
> Here is the condition I'm using, but it's not giving the right result.
>
> $conditions[] = array('Lead.user_id'=>$user_id
> 'or'=>array(
> 'Lead.time_found'=>'>
> '.$this->Session->read('User.start_time'),
> 'Lead.time_found'=>'<
> '.$this->Session->read('User.end_time'),
> 'Lead.user_id'=>array('0',NULL)
> )
> );
>
> Here is what I'm getting back:
> WHERE (`Lead`.`user_id` = 3) AND (((`Lead`.`time_found` < '09:00:00')
> OR (`Lead`.`user_id` IN ('0', NULL) )))
>
> It's leaving out the first start time, and switching some of the AND's
> and OR's.
> What am I doing wrong?
>
> I've also tried just using BETWEEN '$value' in my query, but it ends
> up putting slashes in front of the apostrophes in the sql query which
> makes it invalid (ie. BETWEEN \'2008-01-01\' AND \'2008-02-01\')
>
> Any ideas?
> Thank you!
> Brandon
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---