0

基本的に月のリストであるカレンダーを作成しています。月をクリックすると、その月に開催されるイベントのリストが表示されます。ほとんどのイベントには開始日と終了日がありますが、一部のイベントは終了日に null があり、1 日だけ発生します。

イベントが開始日と終了日の間またはその日に発生する限り、それが発生するすべての月に表示されるはずです。

問題は、終了日が null のイベントが、開始日より後のすべての月にも表示されることです。このクエリを改善して、開始日の月にのみ表示されるようにするにはどうすればよいですか?

コード:

$sql="
SELECT id, event, date_start, date_end FROM events 
WHERE 
(year(date_start) <= $year AND month(date_start) <= $month) 
AND 
($year <= year(date_end) AND $month <= month(date_end) 
OR 
month(date_end) IS NULL)
";

編集:(問題は修正されました...ほぼ?)

$sql="
SELECT id, event, date_start, date_end FROM events 
WHERE 
(year(date_start) <= $year AND month(date_start) <= $month) 
AND 
($year <= year(date_end) AND $month <= month(date_end))
OR
(year(date_start) = $year AND month(date_start) = $month)";
";
4

0 に答える 0