【问题标题】:How to filter records between two different dates Cakephp如何过滤两个不同日期之间的记录 Cakephp
【发布时间】:2014-05-21 12:59:37
【问题描述】:

这是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 个元素...(抱歉 newbi 和法语:P)

【问题讨论】:

  • 除了不使用限制或排序顺序之外 - 问题中的 find 调用会起作用(如果它是有效的 php 代码,而写它不是)。您可以对条件进行细微的更改,但结果有问题吗?如果是这样呢?
  • 您遇到了什么错误或解释您的问题
  • 您的编辑似乎与原始问题无关

标签: php sql cakephp solution


【解决方案1】:

试试这个代码:

$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
));

【讨论】:

  • 伟大的这项工作需要添加这个显示在然后 $this->set('exploits', $exploits);
  • 谢谢大家!谢谢,很高兴快速回答和帮助帮派
猜你喜欢
  • 1970-01-01
  • 2018-09-30
  • 1970-01-01
  • 2021-06-21
  • 2023-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多