如何使用cakephp在同一个字段上提取多个值范围

时间:2016-07-12 05:59:19

标签: cakephp

我已经设定条件以提取价格范围在100-300,800-1000之间的书籍。仅1400-1500,但只获得价格范围1400-1500的书籍。

$options = array(
            'limit'=>20,
            'order'=>'RAND()',
            'contain'=>array(
                'Student' => array(
                    'User'
                ),
                'Book'
            )
        );

$options['contain']['Book']['conditions']['OR']['Book.price BETWEEN ? AND ? '] = array(100,300);
$options['contain']['Book']['conditions']['OR']['Book.price BETWEEN ? AND ? '] = array(800,1000);
$options['contain']['Book']['conditions']['OR']['Book.price BETWEEN ? AND ? '] = array(1400,1500);

1 个答案:

答案 0 :(得分:0)

您好请尝试以下语法,如果有任何问题,请告诉我。

$options = array(
    'limit' => 20,
    'order' => 'RAND()',
    'contain' => array(
        'Student' => array(
            'User'
        ),
        'Book' => array(
            'conditions' => array(
                'or' => array(
                    'Book.price BETWEEN ? AND ? ' => array(100, 300),
                    'Book.price BETWEEN ? AND ? ' => array(800, 1000),
                    'Book.price BETWEEN ? AND ? ' => array(1400, 1500)
                )
            )
        )
    )
);