How can you tell me you looked at the manual, when the example is
right there in complex find conditions?
http://book.cakephp.org/view/74/Complex-Find-Conditions

(I know 'cause I remember adding it :))

$this->Post->find('all', array('conditions'=>array(
                'OR'=>array(array('Post.title LIKE'=>'this'),
                            array('Post.title LIKE'=>'that')
))));

On Nov 5, 3:54 pm, Nick <[EMAIL PROTECTED]> wrote:
> I've been staring at the manual all day... maybe I am missing
> something and if so, my bad.
>
> If I build an or statement without the foreach loop, I would do it as
> follows:
>
> $conditions = array(
>                   'conditions'=> array(
>                                   'OR' => array(
>                                                    'Question.content
> LIKE' => "this",
>                                                    'Question.content
> LIKE' => "that
>                                   )
>                    )
> );
>
> This is the problem, the second Question.content will overwrite the
> first.  Is there any way to build an OR statement where you can look
> for multiple variables within the same database field?
>
> Either way, I think I've accomplished what I set out to by doing the
> following and simply building a regex on the fly, I'd LOVE to know if
> there is a simpler way to do this as I doubt this is the easiest way:
>
>                         $i = 1;
>                         $regString = "^";
>                         $term = $this->data['Question']['searchTerm'];
>                         $splitTerms = explode(" ",$term);
>                         foreach($splitTerms as $splitTerm):
>                                 if (count($splitTerms) != $i){
>                                         $regString = 
> $regString.$splitTerm."{1,}|^";
>                                 } else {
>                                         $regString = 
> $regString.$splitTerm."{1,}";
>                                 }
>                                 $i++;
>                         endforeach;
>                         $conditions = array('conditions'=> 
> array('Question.content REGEXP'
> => "$regString"));
>                         
> $this->set('questions',$this->Question->find('all',$conditions));
>
> On Nov 5, 3:28 pm, teknoid <[EMAIL PROTECTED]> wrote:
>
> > Nothing to do with cake. Your usage is incorrect.
> > Please review how to correctly build an 'OR' condition in the manual,
> > there are multiple examples.
>
> > On Nov 5, 2:45 pm, Nick <[EMAIL PROTECTED]> wrote:
>
> > > Yes, thats my biggest issue, I don't know if there is a way within
> > > Cake to define multiple array values for 'Question.content LIKE'
>
> > > I've tried building it like this, however the SQL query built off of
> > > this array isn't correct:
>
> > > $term = $this->data['Question']['searchTerm'];
> > >                         $splitTerms = explode(" ",$term);
> > >                         foreach($splitTerms as $splitTerm):
> > >                                 $conditions['conditions']['OR']
> > > ['Question.content LIKE'][$i]= ("%
> > > $splitTerm%");
> > >                         $i++;
> > >                         endforeach;
> > > $this->set('questions',$this->Question->find('all',$conditions));
>
> > > On Nov 5, 2:38 pm, teknoid <[EMAIL PROTECTED]> wrote:
>
> > > > Seems like you are overriding your condition each time...
>
> > > > On Nov 5, 1:49 pm, Nick <[EMAIL PROTECTED]> wrote:
>
> > > > > I'm hoping someone can help.  I'm fairly new to CakePHP but am
> > > > > thoroughly enjoying coding with it.
>
> > > > > Basically I've got a field within a table that contains my content.
> > > > > I'm trying to grab the search terms from a single input, explode them
> > > > > and search the content section for each term individually.
>
> > > > > I'm doing something along these lines:
>
> > > > > $term = $this->data['Question']['searchTerm'];
> > > > >                         $splitTerms = explode(" ",$term);
> > > > >                         foreach($splitTerms as $splitTerm):
> > > > >                                 
> > > > > $conditions['conditions']['OR']['Question.content LIKE'] = array("%
> > > > > $splitTerm%");
> > > > >                         endforeach;
> > > > > $this->set('questions',$this->Question->find('all',$conditions));
>
> > > > > My dilemma is basically in setting the conditions... because
> > > > > 'Question.content LIKE' can only contain one value, I can't build an
> > > > > array within my foreach loop that I can then pass to the find method
> > > > > to build a full SQL query.
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to