Reputation: 303
I'm working on a calendar application where you can set events which can last multiple days. On a given date there can be multiple events, already started or starting that day. The user will view everything as a calendar.
Now, my question is: which of the following is the right approach? Is there an even better approach?
1) use 2 tables, events and events_days and store the days of every event in the event_days table
2) use just one table with the events stored with a date_from field and a date_to field and generate every time with mysql and php a list of days for the desired range with the events
Obviously the first option will require much more db storage, while the second one will require a bigger work from the server to generate the list (every single time the user asks for it).
The db storage shouldn't be a problem for now, but i don't know if will be the same in the future. And i fear the second option will need too many resources.
Upvotes: 1
Views: 93
Reputation: 272106
I have used both approaches. Here is a list of pros and cons that I have noticed:
Two tables: events(id)
and events_dates(eventid, date)
Pros:
SELECT eventid FROM events_dates WHERE date BETWEEN '2015-01-01' AND '2015-01-10'
SELECT date FROM events_dates WHERE eventid = 1
Cons:
One table: events(id, start, end)
Cons:
Pros:
Upvotes: 2