i'm developing a read-only weekly calendar view of users's events. Columns are the days of the week (mon > sun) Rows are timeslots (8:00>9:00, 9:00>10:00... from 8AM up to 7PM)
Question: what's the best approach to generate that user calendar:
Option 1: pure SQL I don't even know if that is possible, but i would find it supremelly elegant: have mysql generate a table with 7 columns (the days) and 11 rows (the timeslots) and have subqueries for each timeslot, checking if there is a meeting booked for that timeslot/user.
option 2: php/mysql have mysql just retrieve the meetings booked/user, and cross it with a php-generated calendar.
Is option 1 at all possible? If it is, is it resource-intensive?
Thank you, Alexandre
UPDATE: QUERY SUGGESTIONS
Here is the "option 2" query i use to get the booked events (lessons in this case: the user is a teacher).
SELECT DISTINCT date, hour_from, hour_to, courses.description, courses.alias, teachers.name, locations.new_acronym
FROM timetables
INNER JOIN courses ON (courses.id=timetables.course_id)
INNER JOIN teachers ON (teachers.id=timetables.prof_id)
INNER JOIN locations ON (locations.id=timetables.location_id)
WHERE ((timetables.prof_id='$id')
AND (timetables.date >= '$starting_date')
AND (timetables.date < date_add('$starting_date', INTERVAL 7 day))) ;
I'm very interested for suggestions on a query that would make option 1 work !