Reputation: 2005
I am making an event calendar using jquery, php and mysql. The events created are stored in mysql database and then fetched back and displayed in the calendar. The events contain a start and end date. In case where user wants to create an event which repeats through out say a week, then he can use the recurring property of the calendar and set the recurring end date to one week from event start.
Suppose a user requires a recurring event which dosenot end like birthdays or a weekly event which repeats every week. In this case I think inserting each event into the database for many years is not a good approach. Lets take another case where user creates daily repeating events for 2 years. Here the database will become very populated.
Can someone provide me some idea on how to manage repeating events with no end dates or with very long end dates.
Upvotes: 2
Views: 1817
Reputation: 2425
Maybe you need three tables
Here is a sample event_instance table schema
Here is a sample event_reoccurrence table schema (reoccurrence rules)
Values in #2 - #8 can be a single number, a range "2-6", numbers seperated by commas or null.
So if you check a date and every field is null or it matches that date, then the event happens on that date. Perhaps you could have multiple entries per event to build complex patterns.
Week of month would be first 7 days, not first Sunday. If week_of_month was 3 and day of week was 2, and everything else was null except event ID, it's like the third Tuesday of every month.
Then as the person views the calendar, you request all the reoccurring events against each day of that month and create actual events for each one that matches
Upvotes: 0