Need help from experts!

$result123 = mysql_query("SELECT hours,date2, projekt FROM tidrapport_projekt_timmar WHERE username='$row1[0]' AND date2 BETWEEN '$begin' AND '$end' ORDER BY date2"); $i=1; $n=0; $p=0; while ($row123=mysql_fetch_array($result123)) { if(!empty($row123[hours])) { if($row123[hours]!=null) { ${"datum".$i}=$row123[date2]; ${"timmar".$i}=$row123[hours]; $pre = $i-1; $count = ${"datum".$i}-${"datum".$pre}; if($row123[projekt]=="Sjuk") { $n++; } else { $n=0; } if($n>$_POST[kday]) { $p++; } $i++; } } }

What I want it to do is count days where “$row123[projekt]==“Sjuk”)”;

  1. If number of days “in a row” is above $_POST[kday] I want it to add +1 into variable “a”.
    If not ^^ add +1 to variable “b”.
  2. If number of days between “$row123[projekt]==“Sjuk”)” is under “$_POST[mday]” add +1 to variable “a”.
    If not ^^ add +1 to variable “b”.

Any ideas? I know am on the vurge of solving it but I’m missing something…

Thnx

What is is not doing that it should be doing? Are you getting any errors?

For your and our convenience, and for the benefit of solving this problem as fast as possible, we’d like to request as much information concerning the issue as you can give us :slight_smile:

Hmm…It’s like this… I’ve got a mysql-db set up where people insert their working-hours. If their sick they are reporting that to as where “Sjuk” is in english “sick” :wink:

Lemme see if I get this right:

You want to keep track of the amount of days a person is on sick leave. You’re using a MySQL table for this, of at least the following columns:

  • hours
  • date2
  • projekt
  • username

So if a person reports sick leave, a row is entered into the database, containing the appropriate data.

Now, you want to extract this data in the following way:
If a user has been sick for more than 2 consequential days, you want a variable to be set (and this variable will increase by 1 whenever a 3-or-more-day sick leave occurs on a per-person basis). So far so good, you seem to have gotten this to work.

If a user has reported two occurrances of sick leave that follow each other with an interval smaller than 5 working days, you want another variable to increase (and do so consequently for each occurrance). Correct?

What you could do, is search for any occurrance of ‘10’ (end of sick leave - start of working day), and start counting the occurrances of ‘0’ until you reach a ‘1’ again. If this number is smaller than 5, you could increase the variable by one. After that, you could search for the next occurrance of ‘10’.

This only works when working with a string of 1s and 0s, as posted by you.
Let me know if this worked.

Thnx for your help! :smiley:

Well, I’m not going to do your work for you (after all, doing it yourself is much more fun, it allows you to run into problems, solve them and generally learn), but I’ll see if I can give you some pointers.

Your key function is strpos(). You’ll be using it a couple of times, so it’s good to read up on its syntax, function and realize the possibilities and impossibilities of this function. It’s pretty default, so you should (ab)use it whenever, not just in this script.

You could do something like this:
Find the first occurrance of ‘10’ -> $start (start of sick leave)
Find the first occurrance of ‘01’ -> $end (end of sick leave)
Substract the returned values (amount of days on sick leave)

Increment $start by one
Find the next occurrance of ‘10’ etc. The sequence starts over from here. Be sure to realize that after the increment, the returned value of the start of sick leave should be HIGHER than the last occurrance of $end (and more importantly, realize WHY this should be).

You seem to be up-to-speed about the ++ operator, so I don’t have to elaborate there :wink:

Ahh… I didn’t understand what you ment first BUT!

In mysql it’s not only sick-days it’s also working days!

Print from mysql:
Removed IMG

That shouldn’t a problem. All you have to do is determine ‘sick’ or ‘not sick’, turn it into a string of 1s and 0s and start counting.

Sponsor our Newsletter | Privacy Policy | Terms of Service