Would anybody have any recommendations on a schema for storing opening times of a gym in a database. I want to be able then search different gyms for opening times from e.g 9am onwards and also search for closing times, e.g stays open until 10pm. Baring in mind that certain days will have different opening times.
Would I have to store this as fields like:
Mon_Open
Mon_Close
Tues_Open
etc
etc
Does this sound right? Im quite new to php and SQL so just trying to get my head around a few things for a project I have coming up.
Thanks in advance
Page 1 of 1
How to store opening times
#2
Posted 23 January 2012 - 05:34 PM
I think you're on the right track with this.
Your first column would need to be the Gym_ID and then integer fields for the opening and closing times for each day Mon_Open, Mon_close ... etc.
Then you could search the opening times with something like:
Ideally you would JOIN with your Gym table to get the gym name etc. but one step at a time
Your first column would need to be the Gym_ID and then integer fields for the opening and closing times for each day Mon_Open, Mon_close ... etc.
Then you could search the opening times with something like:
SELECT * FROM `opening_times` WHERE `Mon_close` > 7 ORDER BY `Mon_close` DESC
Ideally you would JOIN with your Gym table to get the gym name etc. but one step at a time
#3
Posted 23 January 2012 - 05:57 PM
websiteprodigy, on 23 January 2012 - 05:34 PM, said:
I think you're on the right track with this.
Your first column would need to be the Gym_ID and then integer fields for the opening and closing times for each day Mon_Open, Mon_close ... etc.
Then you could search the opening times with something like:
Ideally you would JOIN with your Gym table to get the gym name etc. but one step at a time
Your first column would need to be the Gym_ID and then integer fields for the opening and closing times for each day Mon_Open, Mon_close ... etc.
Then you could search the opening times with something like:
SELECT * FROM `opening_times` WHERE `Mon_close` > 7 ORDER BY `Mon_close` DESC
Ideally you would JOIN with your Gym table to get the gym name etc. but one step at a time
thanks dude, at least im pointing in the right direction
#4
Posted 23 January 2012 - 06:21 PM
personally I would have the day as a separate field, so it's not mandatory to search for the day, with the following fields
That way you could search and pull all days that the gym is open at a certain time say
record_id - Primary key gym_id - A key relating to gym info in a gym table opening_time closing_time day
That way you could search and pull all days that the gym is open at a certain time say
- ← PHP Sessions Code Stopping Sessions
- Server Side (PHP, Databases, ASP.NET, etc)
- What's wrong with this PHP code? →
Share this topic:
Page 1 of 1
Help















