Worker-number based on date

Hi everyone!

I’m stuck with an idea where I want to make a script that calculates what “worker-number” an employee has at a given date.
First some information…

Let’s say the workernumbers change in this sequence: 5, 7, 3, 8, 6, 3, 2, 1.

For example on 5th of november:
Worker1 has 5
Worker2 has 7
Worker3 has 3

On 6th of november:
Worker1 has 7
Worker2 has 3
Worker3 has 8

How can I write a script that calculates this automatically based on a “startdate” where I know what number every worker has?

Please feel free to ask questions if you don’t understand what I mean… it’s a bit tricky to explain, but I think I got it right :slight_smile:

I am not sure how you could do this automatically. It all depends on what you have to work with. You could simply switch the day of month, for example:

[php]
$day_of_month = date(‘j’, strtotime(‘2012-11-05’));
switch($day_of_month) {
case 5:
// This is the 5th
break;
}
[/php]

as with what matt said, it all depends on how you have the database set up and if the person can have multiple hours for a given date. If its just a simple table that has the worker and the hours for that date, then do something like what’s above, just change it to a query and display the result. One side though, how you query for the date depends on how it’s stored in the table.

Yes we could use the example above if the Worker1 has 5 on every 1st day of the month if you see what I mean. But in this case that’s not true… The numbersequence does not have anything do to with the date itself.

How is the information stored in the database table?

I haven’t stored it yet in the database because I want so see at different solutions on this problem.
All tips will be greatly appriciated :slight_smile:

Then i would definitely do a database table, maybe 3 tables

table 1 > worker info
wid, auto increment
name
address
blah blah

table 2 > work info
id, auto increment
wid from table 1
date (stored as datetime)
job info

table 3 > hours info
id
wid (from table 1)
jid (id from table 2)
hours on job

From there, you can do a query asking about a specific job, or all the jobs and the amount of hours at that job, or do a query looking at how many hours the person has for a day.

Sponsor our Newsletter | Privacy Policy | Terms of Service