2014-05-11 37 views
0

以下是我的查找條件獲取匹配< =下一個1小時的記錄顯示時間。CakePHP 1.3查找條件與CONCAT多個字段下一個小時記錄

$conditions = array(
    "CONCAT(`showdate`,' ',`hours`,':',`minutes`,':00') <" => "DATE_ADD(NOW(), INTERVAL 1 HOUR)", 
    "CONCAT(`showdate`,' ',`hours`,':',`minutes`,':00') >=" => "NOW()"); 

如果在phpMyAdmin運行相同的查詢 - SQL提示,其工作如下:

SELECT * FROM `showtimes` WHERE CONCAT(`showdate` , ' ', `hours` , ':', `minutes` , ':00') < DATE_ADD(NOW() , INTERVAL 1 HOUR) AND CONCAT(`showdate` , ' ', `hours` , ':', `minutes` , ':00') >= NOW() LIMIT 0 , 30 

以上MySQL查詢運行良好,但是當我用CakePHP的檢查發現,它不工作。

下面是組合了相同:

$conditions = array(
    "CONCAT(`showdate`,' ',`hours`,':',`minutes`,':00') <" => "DATE_ADD(NOW(), INTERVAL 1 HOUR)", 
    "CONCAT(`showdate`,' ',`hours`,':',`minutes`,':00') >=" => "NOW()", 
    ); 

pr($conditions); 
$this->Showtime->recursive = -1; 
$areas = $this->Showtime->find('all', 
      array(
        'conditions' => $conditions, 
        'limit' => $limit, 
        'offset' => $offset, 
        'group' => 'Showtime.id', 
       ) 
      ); 

pr($areas); 

任何幫助或想法將不勝感激。

回答

1

這裏的情況,我發現工作對我來說:

$conditions = array("CONCAT(`hours`,':',`minutes`) <=" => date('H:i', strtotime('+1 hour')), "CONCAT(`hours`,':',`minutes`) >=" => date('H:i')); 

希望它有助於社區成員!

建議隨時歡迎。

+1

「Inventive」解決方案 - 爲此,您應該在數據庫中使用日期函數,而不是進行字符串比較 – AD7six