Jump to content

schedule


leequalls

Recommended Posts

I currently have the below code that reads a database to find what time a staff member is scheduled for work and what day. The below code works fine however on the same day it print lets say they work more then one hour it would show Sunday 2a - 3a, Sunday 3a - 4a, Sunday 4a - 5a ..... and so on I would just like it to simply put Sunday 2a - 5a skipping the extra output.

 

$dayname = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
$shifts = array();
$num=0;
$days=0;

for ($d = 0; $d <= 6; $d++) {
   $slot = mysql_fetch_array(mysql_query("SELECT * FROM rp_timetable WHERE day = '$dayname[$d]'"));
   for ($i = 1; $i <= 24; $i++) {
     $ap1 = "a"; $ap2 = "a";
     if ($slot["$i"] == $eusername) { 
        $one = $i-1; 
        if($one >= 12) { $one = $i-13; if($one == 0) { $one = 12; } $ap1 = "p"; } 
           $two = $i; 
             if($two >= 12) { $two = $i-12; if($two == 0) { $two = 12; } $ap2 = "p"; } 
             $shifts[$num] .= $dayname[$d].' '.$one.''.$ap1.' - '.$two.''.$ap2.' EST<br>';
     $num++;}}   
}

     if($shifts[0] != NULL){ echo"<table><tr><td><strong>Air Shifts:</strong></td><td>"; 
     for ($i = 0; $i <= $num; $i++) { if($i == 0) {echo $shifts[$i].'</td></tr>';} 
                                       else {echo '<tr><td></td><td>'.$shifts[$i].'</td></tr>';} }}
         print"</table>";

Link to comment
https://forums.phpfreaks.com/topic/217527-schedule/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.