RE: [PHP] Calendar Logic Help
| From: | Tommy Pham | Date: | Wed, 20 Oct 2010 16:47:21 +0000 |
| Subject: | RE: [PHP] Calendar Logic Help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-308890@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Floyd Resler [mailto:fresler@adex-intl.com]
> Sent: Wednesday, October 20, 2010 9:17 AM
> To: PHP
> Subject: [PHP] Calendar Logic Help
>
> I'm having problems getting my head around some login for a calendar.
> Specifically, the problem is drawing weekly views for events that span
> multiple days. I've gotten it so that if an event starts in the week
being
> viewed, the days draw correctly for the remainder of the week. However,
if
> the event goes into the next week, its start date is now outside my date
> range and so it doesn't display. I know how to say the logic, I'm not
sure
> how to write it! The logic would be: if any date between the start and
end
> dates of the event are within the week being displayed, show the event.
I'd
> like to put the logic into my MySQL query so I don't have to get all
events
> from the calendar to see what should be displayed. Any ideas?
>
> Thanks!
> Floyd
>
It's hard to give you hints without knowing some actual PHP code and SQL
table columns but here goes:
PHP logic: $event['startDate'] <= $weekEnd && $event['endDate'] >=
$weekStart
Query logic: SELECT * FROM event_table WHERE
start_date <= @weekEnd and
end_date >= @weekStart
week* is the week being viewed. You may have to use the DateTime class or
one of the date_* functions to compare the date for the PHP logic. @ is the
input query parameter. This assumes you have table columns for the event:
start_date & end_date. Adjust the query as needed for multi table joins.
Regards,
Tommy