How do BETWEEN in CAKEPHP?

Asked

Viewed 102 times

1

I’m making a query in the database and need to get information between two column values valor within the specified quantity.

For example: Between the valorMinimo 300 and valorMaximo 600

$imovel = $this->Imovel->find('all', array(
    'conditions' => array(
        'valor' => $queries['valorMin'], 'valor' => $queries['valorMax']
    )
));
  • Performance note: BETWEEN is less efficient than making a >= and <=.

1 answer

3


According to the Cakephp’s own documentation, your condition would be as follows:

$imovel = $this->Imovel->find(
    'all',
    array(
        'conditions' => array('valor BETWEEN ? AND ?' => array(
            $queries['valorMin'],
            $queries['valorMax'])
        )
    )
);

PS: Please test, not my main framework :)

  • You don’t have to stay inside the conditions?

  • @Ricardo is true, I just checked the documentation and that’s right.

  • syntax error, Unexpected T_DOUBLE_ARROW in @Rodrigorigotti

  • @Furlan corrected, check it out.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.