You will need basically three tables here one for Users
another for Calendar
and another for Event
.
And the relationship would be a User
could have many calendars and a Calendar
could have many Events
.
It would probably look like this:
TABLE Name : Users
Fields : userid(auto-incremented), email, username, password(hash), salt
TABLE Name : Calendars
Fields : CalendarID, userid, dateFrom, dateTo, Category
TABLE Name : Events
Fields : EventID, CalendarID, Description
And your SQL would probably look like this:
To get the calendar of a given user would be:
SELECT CalendarID, dateFrom, dateTo, Category
FROM Calendars
WHERE userid = <user id here>
And to get the events of that calendar of a given user would probably look like this:
SELECT Calendars.CalendarID, dateFrom, dateTo, Category, Description
FROM Calendars
INNER JOIN Events
ON Calendars.CalendarID = Events.CalendarID
WHERE userid = <user id here>