How to use OR in find method – CakePHP

cakephp-freelancer-developer

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.

About Rakshit Patel
I am PHP Freelancer, Rakshit Patel AKA WordPress Freelancer working as PHP Programmer India. I am here to share all my developing knowledge, quick coding techniques, quick solutions to save your time and help you guys for any issue or bug fixing. If you have any PHP, WordPress, Magento related work, please contact me. I am interested for the work.

5 Comments on How to use OR in find method – CakePHP

  • strony internetowe kraków
    May 20, 2010 at 7:46 am

    I'm suprised it is so easy and logical, in fact :) Cake never cease to suprise me :)

  • strony internetowe kraków
    May 20, 2010 at 1:16 pm

    I'm suprised it is so easy and logical, in fact :) Cake never cease to suprise me :)

  • Sencaki
    July 8, 2011 at 9:01 am

    thanks guys, that is very help me.. 😀

  • www.wawodwa.pl
    July 31, 2013 at 4:08 pm

    Its fantastic as your other articles : D,
    regards for posting .

Leave a Reply

Your email address will not be published. Required fields are marked *

Sponsors

Sponsors

Recommended

DHgate Computers
DHgate.com - Computers, Cell Phones & more
  • We find everbuying built in php and use css to control the style.

About Author

PHP Freelancer

PHP Freelancer I am PHP Freelancer, Rakshit Patel working as PHP Programmer India. I am here to share all my developing knowledge with you people. For Hire PHP Developer India, contact me.
Follow on twitter: @raxit4u2

Get Free Programming Tutorials:

Become a Fan

Popular Topics

Recent Posts

Most Popular

Recent Comments

Get a Free Quote
$
$
$
Security Question: 3 + 8 = ?
$
 
Listing all pages