Rey Norbert Besmonte
Rey Norbert Besmonte

Reputation: 791

php cake find() using OR condition

I need a basic "or" in my if else condition in php cake.

$oTourRecords =  $this->Record->find('all', array(
    'conditions' => array(
        'record.builder_name' => 'rey',
            'or' => array(
                'record.builder_name' => 'norbert',
            )
         )
     )
);

basically i need to get if the record contain builder_name = rey or "norbert" this one returns null.

Upvotes: 2

Views: 244

Answers (3)

Sumon Sarker
Sumon Sarker

Reputation: 2795

You can also use IN to retrieve similar type of Data instead of OR conditions.

Example :

$oTourRecords =  $this->Record->find('all', array(
        'conditions' => array(
            'record.builder_name IN'=>array(
                 'rey',
                 'norbert'
             )
         )
     )
);

Upvotes: 1

Indrasis Datta
Indrasis Datta

Reputation: 8618

You can do it in several ways:

$oTourRecords =  $this->Record->findAllByBuilderNameOrBuilderName('rey', 'norbert');

$oTourRecords =  $this->Record->find('all', array(
        'conditions' => array(
            'OR' => array(
                    'record.builder_name' => 'norbert',
                    'record.builder_name' => 'rey',
                )
        )
     ));

$oTourRecords =  $this->Record->find('all', array(
        'conditions' => array('record.builder_name IN ' => array('norbert','rey'))
 ));

Upvotes: 2

tarikul05
tarikul05

Reputation: 1913

Try

$oTourRecords =  $this->Record->find('all', array(
            'conditions' => array(
                'OR' => array(
                        'record.builder_name' => 'norbert',
                        'record.builder_name' => 'rey',
                    )
            )
         ));

Upvotes: 4

Related Questions