how to store this data in mysql

Joined
12 Feb 2006
Posts
17,313
Location
Surrey
i'm creating a part of my web app where staff times are created dynamically each month based on the date they started at a site, the frequency of which they work (e.g. mon, wed, fri) and the hours they do, e.g. 2.5 mon, 3 hours wed, 2.5 fri etc.

at the moment i go to each staffs times this month and it's displayed as follows,

Michelle May 2015.
- Total Hours - 34.5 over 13 days
- Friday 01/05 : 6pm - 8.30pm : 2.5 hours
- Monday 04/05 : 6pm - 8.30pm : 2.5 hours
- Wednesday 06/05 : 6pm - 8pm : 3 hours
- Friday 08/05 : 6pm - 8.30pm : 2.5 hours
- Monday 11/05 : 6pm - 8.30pm : 2.5 hours
- Wednesday 13/05 : 6pm - 8pm : 3 hours
- Friday 15/05 : 6pm - 8.30pm : 2.5 hours
- Monday 18/05 : 6pm - 8.30pm : 2.5 hours
- Wednesday 20/05 : 6pm - 8pm : 3 hours
- Friday 22/05 : 6pm - 8.30pm : 2.5 hours
- Monday 25/05 : 6pm - 8.30pm : 2.5 hours
- Wednesday 27/05 : 6pm - 8pm : 3 hours
- Friday 29/05 : 6pm - 8.30pm : 2.5 hours

this is just for one site and the staff may have 2/3 sites per month.

what i'd like to do is have the info stored in different fields for the following: staffId, month, year, total hours, total days, and then the days they've worked in one field, which i can break up with php at a later point if needed, but saving me having a massive load of fields. how best would it be to store it so that it can easily be taken apart, e.g.

[date][starttime][endtime]

unless with that said, would it be better to have the above stored on another table which is linked to this one?
 
Soldato
Joined
28 Aug 2006
Posts
3,003
I'd probably split all the fields up into a couple of tables.

Code:
Table #1 : Staff
StaffID, Name, ...

Table #2 : Sites
SiteID, Name, ...

Table #3 : Staff_Sites
StaffSiteID, StaffID, SiteID, Date, ...

Table #4: StaffTimes
StaffTimesID, StaffID, SiteID, Date, StartTime, EndTime, ...

Other fields can be auto generated on the fly within your app, based on the database results.
 
Back
Top Bottom