Jamie
asked on
Create MySQL view instead of static table for xx minute timeslots within a given date period
Hello Experts,
I using PHP/MySQL have the following mysql config table, with the following fields and values - where the values can change periodically;
Column Value Desc
Timeslot 20 minutes
MonOpen 14:00 time open in 24 hour notation
MonClosed 18:00 time closed in 24 hour notation
TueOpen 08:00 time open in 24 hour notation
TueClosed 18:00 time closed in 24 hour notation
WedOpen 08:00 time open in 24 hour notation
WedClosed 18:00 time closed in 24 hour notation
ThuOpen 08:00 time open in 24 hour notation
ThuClosed 19:00 time closed in 24 hour notation
FruOpen 06:20 time open in 24 hour notation
FriClosed 20:00 time closed in 24 hour notation
SatOpen 06:00 time open in 24 hour notation
SatClosed 13:00 time closed in 24 hour notation
SunOpen 00:00 time open in 24 hour notation
SunClosed 00:00 time closed in 24 hour notation
For any date range, I currently create a static table for all available xx mins timeslots.
My question is, given a range of dates, is it possible to create a MySQL view instead as this would stop the table growing over a period of time.
Many thanks
Regards
Jamie
I using PHP/MySQL have the following mysql config table, with the following fields and values - where the values can change periodically;
Column Value Desc
Timeslot 20 minutes
MonOpen 14:00 time open in 24 hour notation
MonClosed 18:00 time closed in 24 hour notation
TueOpen 08:00 time open in 24 hour notation
TueClosed 18:00 time closed in 24 hour notation
WedOpen 08:00 time open in 24 hour notation
WedClosed 18:00 time closed in 24 hour notation
ThuOpen 08:00 time open in 24 hour notation
ThuClosed 19:00 time closed in 24 hour notation
FruOpen 06:20 time open in 24 hour notation
FriClosed 20:00 time closed in 24 hour notation
SatOpen 06:00 time open in 24 hour notation
SatClosed 13:00 time closed in 24 hour notation
SunOpen 00:00 time open in 24 hour notation
SunClosed 00:00 time closed in 24 hour notation
For any date range, I currently create a static table for all available xx mins timeslots.
My question is, given a range of dates, is it possible to create a MySQL view instead as this would stop the table growing over a period of time.
Many thanks
Regards
Jamie
ASKER
Hello Ray,
Apologies for the delay in getting back to you.
Many thanks for looking at this and the great solution you have suggested and provided in demo form. Whilst I can see where I would use this, I do need access to the timeslots directly from MySQL as I have other database tables which need to cross reference the static 'timeslots' table - which is ideally why I need it as view instead;
e.g for Monday 19th September to Tuesday 20th September, the 'timeslots' view would contain;
19/09/2016 14:00:00
19/09/2016 14:20:00
19/09/2016 14:40:00
19/09/2016 15:00:00
19/09/2016 15:20:00
19/09/2016 15:40:00
19/09/2016 16:00:00
19/09/2016 16:20:00
19/09/2016 16:40:00
19/09/2016 17:00:00
19/09/2016 17:20:00
19/09/2016 17:40:00
19/09/2016 18:00:00
20/09/2016 08:00:00
20/09/2016 08:20:00
20/09/2016 08:40:00
20/09/2016 09:00:00
20/09/2016 09:20:00
20/09/2016 09:40:00
20/09/2016 10:00:00
20/09/2016 10:20:00
20/09/2016 10:40:00
20/09/2016 11:00:00
20/09/2016 11:20:00
20/09/2016 11:40:00
20/09/2016 12:00:00
20/09/2016 12:20:00
20/09/2016 12:40:00
20/09/2016 13:00:00
20/09/2016 13:20:00
20/09/2016 13:40:00
20/09/2016 14:00:00
20/09/2016 14:20:00
20/09/2016 14:40:00
20/09/2016 15:00:00
20/09/2016 15:20:00
20/09/2016 15:40:00
20/09/2016 16:00:00
20/09/2016 16:20:00
20/09/2016 16:40:00
20/09/2016 17:00:00
20/09/2016 17:20:00
20/09/2016 17:40:00
20/09/2016 18:00:00
As a static table, 1 year of 20 min slots is around 11,000 rows, which would grow by that amount each year. I got a couple of ideas on how to manage the static table through code, but I thought, a view, if possible, would crack this nut in one action.
Many thanks
Regards
Jamie
Apologies for the delay in getting back to you.
Many thanks for looking at this and the great solution you have suggested and provided in demo form. Whilst I can see where I would use this, I do need access to the timeslots directly from MySQL as I have other database tables which need to cross reference the static 'timeslots' table - which is ideally why I need it as view instead;
e.g for Monday 19th September to Tuesday 20th September, the 'timeslots' view would contain;
19/09/2016 14:00:00
19/09/2016 14:20:00
19/09/2016 14:40:00
19/09/2016 15:00:00
19/09/2016 15:20:00
19/09/2016 15:40:00
19/09/2016 16:00:00
19/09/2016 16:20:00
19/09/2016 16:40:00
19/09/2016 17:00:00
19/09/2016 17:20:00
19/09/2016 17:40:00
19/09/2016 18:00:00
20/09/2016 08:00:00
20/09/2016 08:20:00
20/09/2016 08:40:00
20/09/2016 09:00:00
20/09/2016 09:20:00
20/09/2016 09:40:00
20/09/2016 10:00:00
20/09/2016 10:20:00
20/09/2016 10:40:00
20/09/2016 11:00:00
20/09/2016 11:20:00
20/09/2016 11:40:00
20/09/2016 12:00:00
20/09/2016 12:20:00
20/09/2016 12:40:00
20/09/2016 13:00:00
20/09/2016 13:20:00
20/09/2016 13:40:00
20/09/2016 14:00:00
20/09/2016 14:20:00
20/09/2016 14:40:00
20/09/2016 15:00:00
20/09/2016 15:20:00
20/09/2016 15:40:00
20/09/2016 16:00:00
20/09/2016 16:20:00
20/09/2016 16:40:00
20/09/2016 17:00:00
20/09/2016 17:20:00
20/09/2016 17:40:00
20/09/2016 18:00:00
As a static table, 1 year of 20 min slots is around 11,000 rows, which would grow by that amount each year. I got a couple of ideas on how to manage the static table through code, but I thought, a view, if possible, would crack this nut in one action.
Many thanks
Regards
Jamie
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Ray,
Many thanks for all your help with this, great advice and article, It has been invaluable, given me the solution and shown other possibilities for my future coding needs - very much appreciated.
Best Regards
Jamie
Many thanks for all your help with this, great advice and article, It has been invaluable, given me the solution and shown other possibilities for my future coding needs - very much appreciated.
Best Regards
Jamie
https://iconoun.com/demo/temp_jamwales.php
Open in new window
Outputs something like:Open in new window