LoginSignup
6
6

More than 5 years have passed since last update.

複数の範囲を BETWEEN で抽出する時、こんなベタなテクニックが必要ですか?

Last updated at Posted at 2012-03-16

Hoge モデルから find する時、複数の範囲を BETWEEN で抽出したい時が
あります。サンプルを添付します。

しかし、PHP の連想配列としてみると、'Hoge.time BETWEEN ? AND ?' は
複数存在することになるため、一方が削られます。そのため私はいつも上
のように、後者の最後にスペースを入れて削られないようにしています。
他に良い方法はありますか?

$condition = array("OR" => array(
                     'Hoge.time BETWEEN ? AND ?' => array(8888, 9999),
                     'Hoge.time BETWEEN ? AND ? ' => array(0000, 1111)));
$this->Hoge->find('all', array('conditions' => $condition));

6
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6