如何过滤两个不同日期之间的记录 Cakephp

问题描述 投票:0回答:1

这是SQL中的解决方案

SELECT * 
FROM  exploits
WHERE  date
BETWEEN  '2014-01-01'
AND  '2014-12-31'
ORDER BY  exploits.date DESC 
LIMIT 0 , 30

这是我在 CakePhp 中的解决方案(完全是新手)

$exploits = $this->Exploit->find('all', array(
               'conditions' => array(
               'Exploit.date BETWEEN 2014-01-01 AND 2014-12-31')
            $this->set('exploits', $exploits);

    }

谢谢您的帮助

======

尝试新代码时

错误:发生内部错误。

在此之前我所拥有的 `私有函数_index_action(){

    $exploits = $this->Exploit->find('all', array(
        'conditions' => array(
            'is_published' => 1),
        'limit' => 6,
        'recursive' => -1,`

但我想尝试只显示日期之间的 6 个元素...(对不起新手和法语:P)

php sql cakephp
1个回答
2
投票

试试这个代码:

$exploits = $this->Exploit->find('all', array(
    'conditions' => array(
        'Exploit.date between ? and ?'=> array('2014-01-01', '2014-12-31'),
    ),
    'order' => array('date' => 'desc'),
    'limit'=>30
));
© www.soinside.com 2019 - 2024. All rights reserved.