I have the following db for a fitness club calendar and booking system. I get omc_courses details which joined to omc_date,omc_week etc.
Now I also want to display total booked numbers for each course.
I thought two ways to do it and I'd like to know your opinions which way is better or if there are any better ways to do it.
My method one.
Adding and deleting one to/from omc_courses.booked whenever a member booked or cancel the booking.
My method two.
Count omc_bookings by course_id, grouped_by course_id and add this number to omc_courses.booked.
Thanks in advance.
CREATE TABLE IF NOT EXISTS `omc_bookings` (
`booking_id` int(11) NOT NULL AUTO_INCREMENT,
`customer_id` int(11) NOT NULL,
`course_id` int(11) NOT NULL,
`date_enroll` date NOT NULL,
PRIMARY KEY (`booking_id`)
) .... ;
CREATE TABLE IF NOT EXISTS `omc_courses` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date_id` int(10) DEFAULT NULL,
`time` time NOT NULL,
`course_name` varchar(255) DEFAULT NULL,
`trainer_id` int(11) DEFAULT NULL,
`desc` varchar(255) DEFAULT NULL,
`capacity` int(11) DEFAULT NULL,
`active` tinyint(1) NOT NULL DEFAULT '1',
`order` int(11) DEFAULT NULL,
`booked` int(5) DEFAULT NULL,
`type` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ..... ;
there are more like omc_date, omc_week etc.