데이터베이스에서 예정된 이벤트를 표시해야합니다. 문제는 현재 진행중인 시작일의 이벤트를 현재 사용하고있는 쿼리를 사용할 때 현재 이벤트에 관계없이 다가오는 이벤트 목록에 더 낮게 표시됩니다.SQL 시작일과 종료일로 예정된 이벤트를 선택하는 쿼리
내 테이블 (yaml) :
columns:
title:
type: string(255)
notnull: true
default: Untitled Event
start_time:
type: time
end_time:
type: time
start_day:
type: date
notnull: true
end_day:
type: date
description:
type: string(500)
default: This event has no description
category_id: integer
내 쿼리 (교리) :
$results = Doctrine_Query::create()
->from("sfEventItem e, e.Category c")
->select("e.title, e.start_day, e.description, e.category_id, e.slug")
->addSelect("c.title, c.slug")
->orderBy("e.start_day, e.start_time, e.title")
->limit(5)
->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
은 기본적으로 저는 현재 진행되고있는 이벤트를하고 싶은 상단에로 (그렇다면 오늘 START_DAY와 END_DAY 사이입니다) 명부. 가능하다면 어떻게해야합니까? Raw SQL 쿼리는 DQL로 전환하기가 쉽기 때문에 좋은 대답이기도합니다. 아래 답변 중 하나를 기반으로
솔루션 는 :
$results = Doctrine_Query::create()
->from("sfEventItem e, e.Category c")
->select("e.title, e.start_day, e.description, e.category_id, e.slug")
->addSelect("c.title, c.slug")
->addSelect("IF(NOW() BETWEEN e.start_day AND e.end_day,0,1) as score")
->orderBy("score, e.start_day, e.start_time, e.title")
->limit(5)
->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
그건 꽤 깔끔하고 약간의 수정으로 작동했습니다. (어떤 이유로 doctrine은 orderBy 일 때 어떤 레코드라도 선택하지 않았습니다) –