cakephp 1.3查找所有现在和将来的最多5条记录

时间:2013-03-21 17:34:00

标签: php sql cakephp-1.3

我无法获得查询以返回预期结果。从cakephp 1.1迁移到1.3。目前,我的新查询不会返回任何结果。一旦我得到结果,我需要限制为5.我的$sqlConditions数组中的now()是否正确?有什么建议?谢谢你的期待。

旧查询cakephp 1.1:

function listcomingevents() {
    $conditions="EventsDate.start_date>=now()";
    $this->weekevent="EventsDate.start_date ASC";
    $listcomingeventdata=$this->EventsDate->findAll($conditions,'',$this->weekevent,'5');
    return $listcomingeventdata;
}

新查询cakephp 1.3:

function listcomingevents() {
    $sqlConditions = array( "EventsDate.start_date >="=>"now()");

    //remaining code
    $sqlOrderBy = array("EventsDate.start_date asc");
    $sqlParams = array('conditions'=>$sqlConditions,'order'=>$sqlOrderBy);
    $listcomingeventdata=$this->EventsDate->find('all',$sqlParams);
    return $listcomingeventdata;
}

也尝试过:

$sqlConditions = array("EventsDate.start_date >="=>"CURDATE()");   

1 个答案:

答案 0 :(得分:1)

只需将NOW()表达式直接放在左侧,例如

   $sqlConditions = array( "EventsDate.start_date >= CURDATE()");