Home > CakePHP, Php programming > How to use OR in find method – CakePHP

How to use OR in find method – CakePHP

Hello Friends,

When any developer is working with any web application, he/she will constantly interact with the Select Query. As i am working with CakePHP, i also need to use Select Query often. For Select Query in CakePHP, you can use find method of Model which gives you the data as per conditions given in find method. If you write more than one conditions in conditions array passed in find method than by default it will take OR clause and make a query string with “AND“. If you want to do OR operation or any other operation than you need to mention that in find method. Look at below syntax.

 <?php
$this->Post->find(‘all’, array(‘conditions’ => $conditions));
$conditions = array(“id”=>”5″,”name”=>”abc”);
//Above condition will make a select query with AND.(WHERE id=5 AND name=’abc’)
$conditions = array(“OR”=>array(“id”=>”5″,”name”=>”abc”));
// If you define “OR” as per above statement than the query will be WHERE id=5 OR name=’abc’
?>
If you find any problem in this than let me know by comment.
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: