PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, March 17, 2022

[FIXED] CakePHP - select from database with condition

 March 17, 2022     cakephp, multiple-conditions     No comments   

Issue

I have this selector:

$this->Table->find('list',array('contain'=>false,'conditions'=>array('status'=>1,'unit_id'=>null,'country_id'=>$countryId,'eday'=>$eday),'fields'=>'id'));

And this works perfect. But now i need to have another one i cant find how to do this ;)

I need to select all records from Table but with condition:

'eday'>=$eday AND 'eday'<$eday+7 

Its this posibble in easy way? Maybe this is stupid question but i dont have exp in PHP ;)


Solution

In cakephp the equivalent for and condition is
Example: column1 = 'value' AND column2 = 'value'

'AND' => array(
    'column1' => 'value',
    'column2' => 'value'
)

So your query builder would be like this

$this->Table->find('list',array(
    'contain' => false,
    'conditions' => array(
        'status' => 1,
        'unit_id' => null,
        'country_id' => $country,
        'AND' => array(
            'eday >=' => $eday,
            'eday <' => ($eday+7)
        )
    ),
    'fields'=>'id'
));


Answered By - Beginner
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing