appeland Posted September 29, 2006 Share Posted September 29, 2006 Hello,this troubles me for a couple of month now, I haven't started writing anything and it's not urgent to, it's one of them fun-to-do-sometime projects ::)I would like to create a staffing schedule calendar and I am wondering how todo the database layout for this. The easiest way would be to have one field in the DB per day and per employee but that'll obviously generate masses of data.I also thought to have a database field per month per employee and then delimiting each day with some character, and sub- definitions of the day with another character.Would you have any input into this please.Thansk & Regards,Andi Quote Link to comment Share on other sites More sharing options...
Jenk Posted September 29, 2006 Share Posted September 29, 2006 Off the top of my head, I'd use two tables; Employees and Dates (with emp_id as foreign key)Employees contains only employee info.Dates contains three fields, week_id INT and emp_id INT shift_pattern INT.Then use bitwise to denote which days people will work.Can then use queries like:[code]SELECT `employee`.`name`, `dates`.`shift_pattern`FROM `employees`JOIN `dates`ON `employees`.`emp_id` = `dates`.`emp_id`WHERE `dates`.`emp_id` = 1;[/code]then use bitwise comparison to see which days someone works:[code]<?php$row = mysql_fetch_assoc($result);$days = array( 1 => 'Sun', 2 => 'Mon', 4 => 'Tue', 8 => 'Wed', 16 => 'Thur', 32 => 'Fri', 64 => 'Sat');for ($i = 1; $i < 64; $i += $i){ if ($row['shift_pattern'] ^ $i) echo "{$row['name']} is working on {$days[$i]}<br />\n";}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.