2012-07-25 3 views
0

내 문제는 매우 간단합니다. 나는 'articles'이라는 테이블을 가지고 있으며, 최근 3 개의 최근 기사에서 DESC를 주문하고 싶습니다. 그러나 발행일이 오늘보다 높거나 같으면이 기사도 표시되기를 바랍니다. 그래서 나는 나의 요청에 다른 조건을 가졌다.SQL 요청이 올바르게 작동하지 않습니다.

$this->set('lastArticles', $this->Article->find('all', array(
      'conditions' => array('Article.visible' => true), 
      'Article.publication_date <= ' => date('Y-m-d'), 
      'order' => array('Article.creation_date DESC', 'Article.id DESC'), 
      'limit' => 3 
     ))); 

그러나 문제는> 날짜 ('Y-m-D') 게시 날짜가 기사가이 사람이 너무 표시되는 경우에도입니다 : 내 CakePHP의 코드는 다음과 같습니다! 누구나 아이디어가 있습니까? 당신의 대답에 미리 감사드립니다.

답변

1

귀하의 publication_date 조건이 조건 배열에없는 것 같습니다. 귀하의 코드는 다음과 같아야합니다 :

$this->set('lastArticles', $this->Article->find('all', 
    array(
     'conditions' => array(
      'Article.visible' => true, 
      'Article.publication_date <= ' => date('Y-m-d') 
     ), 
     'order' => array(
      'Article.creation_date DESC', 
      'Article.id DESC' 
     ), 
     'limit' => 3 
    ))); 

약간의 들여 쓰기 및 공백은 귀하의 친구입니다.

+0

답장을 보내 주셔서 감사합니다. 난 당신의 솔루션을 시도하고 그것은 작동하지 않습니다. 그럼에도 불구하고 기사의 발행일은 2012-07-31이므로 표시해서는 안됩니다! – user1450730

0
See this 

$conditions = array(
       'Article.visible' => true, 
       'Article.publication_date <= ' => date('Y-m-d') 
      ); 

$order = array('Article.creation_date DESC', 'Article.id DESC'); 

$lastArticles = $this->Article->find('all', array(
      'conditions' => $conditions, 
      'order' => $order, 
      'limit' => 3 
     ); 

$this->set('lastArticles', $lastArticles); 
관련 문제