RE: [PHP] Head Twister: Need Help Please
| From: | Jack Dempsey | Date: | Sun, 20 Apr 2003 01:59:26 +0000 |
| Subject: | RE: [PHP] Head Twister: Need Help Please | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144516@lists.php.net to get a copy of this message | ||
hey jeff,
i saw another solution just posted, but here's mine:
<?php
$first_crew = 4;
$first_off = 2;
$crew_cntr = $first_crew;
$off_cntr = $first_off;
$duty_schedule = array();
$days_in_current_month = date("t");
for($i=1; $i <= $days_in_current_month; $i++){
if($crew_cntr != $off_cntr){
$duty_schedule[$i] = $crew_cntr;
$crew_cntr = ($crew_cntr % 7) + 1;
} else {
$crew_cntr = ($crew_cntr % 7) + 1;
$off_cntr = ($off_cntr % 7) + 1;
$duty_schedule[$i] = $crew_cntr;
$crew_cntr++;
}
}
?>
using april as the test, all you have to do is set the crew of the first
day, and the first crew that gets off...
the loop then generates the schedule for that month...it'd be easy then to
tie this into something that either reads from a config file, or that just
generates the years schedule, etc...
best of luck,
jack
> -----Original Message-----
> From: Jeffrey L. Fitzgerald [mailto:mailgroups@jlfx.com]
> Sent: Saturday, April 19, 2003 8:24 PM
> To: php-general@lists.php.net
> Subject: [PHP] Head Twister: Need Help Please
>
>
>
> Hello,
>
> I am trying to build a PHP script that can tell the members
> of our fire
> department what crew is working on a given night, after selecting a date.
> The shifts are awkward and I originally builta very primitive way to
> display who's on duty (below). But I know this is not the right way to do
> it, and also won't allow for a member to select a given future date and
> find out. Each crew has a bye week so,
> it's like a given week: 1(bye) 2,3,4,5,6,7, then 1,2(bye), 3,4,5,6,7,
> then 1,2,3(bye),4,5,6,7 and so on...
>
> I think I'm cross eyed after trying to write a script that
> would determine
> the day of the year (date("z") and then do the math to get the number. If
> you feel led to help out the fire department pleeeze do :-)... BTW, you
> can see the old script below working at the top of www.svfd.org
>
> Thanks, Jeff
>
>
>
> <?php
> $crewMar =
>
> array(1=>"3","5","6","7","1","2","3","4","6","7","1","2","3","4","
>
> 5","7","1","2","3","4","5","6","1","2","3","4","5","6","7","2","3");
> $crewApr =
>
> array(1=>"4","5","6","7","1","3","4","5","6","7","1","2","4","5","
>
> 6","7","1","2","3","5","6","7","1","2","3","4","6","7","1","2");
> $crewMay =
>
> array(1=>"3","4","5","7","1","2","3","4","5","6","1","2","3","4","
>
> 5","6","7","2","3","4","5","6","7","1","3","4","5","6","7","1","2");
>
> $day = date("j");
> $month = date("F");
>
> print (date ("l F dS, Y"));
>
> print (" ");
>
> if ($month == "March") { print ("Crew
> $crewMar[$day] is on duty");}
> if ($month == "April") { print ("Crew
> $crewApr[$day] is on duty");}
> ?>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>