0

私は、週の始まりが水曜日で終わりが火曜日であるスケジュール スクリプトに取り組んでいます。私はずっと研究しており、水曜日に週を開始する方法を見つけていますが、DAYOFWEEKまたはWEEKDAYの使用に応じて、最終日は常に土曜日または日曜日に終了します。

私のコードは、7日間のそれぞれについて今のままです...

                <td class="hours" colspan="2">
            <?php $hour3 = mysql_query("SELECT h.* FROM hours AS h, employees AS e 
                                        WHERE h.s_id = '" .$s_id. "' AND e.u_id = h.u_id AND DAYOFWEEK(h.date) = 4
                                        ORDER BY e.emp_id ASC");
            while($time3 = mysql_fetch_array($hour3)) { ?>

                <div class="hours">
                    <?php $starting = date("g:ia", strtotime($time3['timestart']));
                        $ending = date("g:ia", strtotime($time3['timeend']));
                            if ($time3['work'] == '1') {
                                if ($time3['why_off'] == '1') 
                                    {echo "<div class='off'>OFF [R]</div>";}
                                elseif ($time3['why_off'] == '2') 
                                    {echo "<div class='off'>OFF [ML]</div>";}
                                elseif  ($time3['why_off'] == '0')
                                    {echo "<div class='off'>OFF</div>";}
                            }
                                elseif ($time3['work'] == '0') {
                                    if ($time3['work_type'] == '1') {
                                        if ($time3['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[TL]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[TL]</div>";}
                                    }
                                    elseif ($time3['work_type'] == '2') {
                                        if ($time3['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[SF]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[SF]</div>";}
                                    }
                                    elseif ($time3['work_type'] == '3') {
                                        if ($time3['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[-/+]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[-/+]</div>";}
                                    }
                                    elseif ($time3['work_type'] == '4') {
                                        if ($time3['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[TR]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[TR]</div>";}
                                    }
                                    elseif ($time3['work_type'] == '0') {
                                        if ($time3['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."</div>";}
                                    }
                                }?>

                </div>
                <?php } ?>

            </td>
            <td class="hours" colspan="2">
            <?php $hour4 = mysql_query("SELECT h.* FROM hours AS h, employees AS e 
                                        WHERE h.s_id = '" .$s_id. "' AND e.u_id = h.u_id AND DAYOFWEEK(h.date) = 5 
                                        ORDER BY e.emp_id ASC");
            while($time4 = mysql_fetch_array($hour4)) { ?>

                <div class="hours">
                    <?php $starting = date("g:ia", strtotime($time4['timestart']));
                        $ending = date("g:ia", strtotime($time4['timeend']));
                            if ($time4['work'] == '1') {
                                if ($time4['why_off'] == '1') 
                                    {echo "<div class='off'>OFF [R]</div>";}
                                elseif ($time4['why_off'] == '2') 
                                    {echo "<div class='off'>OFF [ML]</div>";}
                                elseif  ($time4['why_off'] == '0')
                                    {echo "<div class='off'>OFF</div>";}
                            }
                                elseif ($time4['work'] == '0') {
                                    if ($time4['work_type'] == '1') {
                                        if ($time4['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[TL]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[TL]</div>";}
                                    }
                                    elseif ($time4['work_type'] == '2') {
                                        if ($time4['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[SF]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[SF]</div>";}
                                    }
                                    elseif ($time4['work_type'] == '3') {
                                        if ($time4['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[-/+]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[-/+]</div>";}
                                    }
                                    elseif ($time4['work_type'] == '4') {
                                        if ($time4['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[TR]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[TR]</div>";}
                                    }
                                    elseif ($time4['work_type'] == '0') {
                                        if ($time4['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."</div>";}
                                    }
                                }?>

                </div>
                <?php } ?>

            </td>
            <td class="hours" colspan="2">
            <?php $hour5 = mysql_query("SELECT h.* FROM hours AS h, employees AS e 
                                        WHERE h.s_id = '" .$s_id. "' AND e.u_id = h.u_id AND DAYOFWEEK(h.date) = 6 
                                        ORDER BY e.emp_id ASC");
            while($time5 = mysql_fetch_array($hour5)) { ?>

                <div class="hours">
                    <?php $starting = date("g:ia", strtotime($time5['timestart']));
                        $ending = date("g:ia", strtotime($time5['timeend']));
                            if ($time5['work'] == '1') {
                                if ($time5['why_off'] == '1') 
                                    {echo "<div class='off'>OFF [R]</div>";}
                                elseif ($time5['why_off'] == '2') 
                                    {echo "<div class='off'>OFF [ML]</div>";}
                                elseif  ($time5['why_off'] == '0')
                                    {echo "<div class='off'>OFF</div>";}
                            }
                                elseif ($time5['work'] == '0') {
                                    if ($time5['work_type'] == '1') {
                                        if ($time5['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[TL]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[TL]</div>";}
                                    }
                                    elseif ($time5['work_type'] == '2') {
                                        if ($time5['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[SF]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[SF]</div>";}
                                    }
                                    elseif ($time5['work_type'] == '3') {
                                        if ($time5['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[-/+]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[-/+]</div>";}
                                    }
                                    elseif ($time5['work_type'] == '4') {
                                        if ($time5['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[TR]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[TR]</div>";}
                                    }
                                    elseif ($time5['work_type'] == '0') {
                                        if ($time5['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."</div>";}
                                    }
                                }?>

                </div>
                <?php } ?>

            </td>
            <td class="hours" colspan="2">
            <?php $hour6 = mysql_query("SELECT h.* FROM hours AS h, employees AS e 
                                        WHERE h.s_id = '" .$s_id. "' AND e.u_id = h.u_id AND DATE_ADD((DAYOFWEEK(h.date) = 7), INTERVAL 7 DAY)
                                        ORDER BY e.emp_id ASC");
            while($time6 = mysql_fetch_array($hour6)) { ?>

                <div class="hours">
                    <?php $starting = date("g:ia", strtotime($time6['timestart']));
                        $ending = date("g:ia", strtotime($time6['timeend']));
                            if ($time6['work'] == '1') {
                                if ($time6['why_off'] == '1') 
                                    {echo "<div class='off'>OFF [R]</div>";}
                                elseif ($time6['why_off'] == '2') 
                                    {echo "<div class='off'>OFF [ML]</div>";}
                                elseif  ($time6['why_off'] == '0')
                                    {echo "<div class='off'>OFF</div>";}
                            }
                                elseif ($time6['work'] == '0') {
                                    if ($time6['work_type'] == '1') {
                                        if ($time6['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[TL]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[TL]</div>";}
                                    }
                                    elseif ($time6['work_type'] == '2') {
                                        if ($time6['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[SF]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[SF]</div>";}
                                    }
                                    elseif ($time6['work_type'] == '3') {
                                        if ($time6['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[-/+]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[-/+]</div>";}
                                    }
                                    elseif ($time6['work_type'] == '4') {
                                        if ($time6['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[TR]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[TR]</div>";}
                                    }
                                    elseif ($time6['work_type'] == '0') {
                                        if ($time6['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."</div>";}
                                    }
                                }?>

                </div>
                <?php } ?>

            </td>
            <td class="hours" colspan="2">
            <?php $hour0 = mysql_query("SELECT h.* FROM hours AS h, employees AS e 
                                        WHERE h.s_id = '" .$s_id. "' AND e.u_id = h.u_id AND DATE_ADD((DAYOFWEEK(h.date) = 1), INTERVAL 7 DAY)
                                        ORDER BY e.emp_id ASC");
            while($time0 = mysql_fetch_array($hour0)) { ?>

                <div class="hours">
                    <?php $starting = date("g:ia", strtotime($time0['timestart']));
                        $ending = date("g:ia", strtotime($time0['timeend']));
                            if ($time0['work'] == '1') {
                                if ($time0['why_off'] == '1')
                                    {echo "<div class='off'>OFF [R]</div>";}
                                elseif ($time0['why_off'] == '2')
                                    {echo "<div class='off'>OFF [ML]</div>";}
                                elseif  ($time0['why_off'] == '0')
                                    {echo "<div class='off'>OFF</div>";}
                            }
                                elseif ($time0['work'] == '0') {
                                    if ($time0['work_type'] == '1') {
                                        if ($time0['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[TL]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[TL]</div>";}
                                    }
                                    elseif ($time0['work_type'] == '2') {
                                        if ($time0['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[SF]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[SF]</div>";}
                                    }
                                    elseif ($time0['work_type'] == '3') {
                                        if ($time0['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[-/+]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[-/+]</div>";}
                                    }
                                    elseif ($time0['work_type'] == '4') {
                                        if ($time0['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[TR]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[TR]</div>";}
                                    }
                                    elseif ($time0['work_type'] == '0') {
                                        if ($time0['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."</div>";}
                                    }
                                }?>

                </div>
                <?php } ?>

            </td>
            <td class="hours" colspan="2">
            <?php $hour1 = mysql_query("SELECT h.* FROM hours AS h, employees AS e 
                                        WHERE h.s_id = '" .$s_id. "' AND e.u_id = h.u_id AND DATE_ADD((DAYOFWEEK(h.date) = 2), INTERVAL 7 DAY)
                                        ORDER BY e.emp_id ASC");
            while($time1 = mysql_fetch_array($hour1)) { ?>

                <div class="hours">
                    <?php $starting = date("g:ia", strtotime($time1['timestart']));
                        $ending = date("g:ia", strtotime($time1['timeend']));
                            if ($time1['work'] == '1') {
                                if ($time1['why_off'] == '1') 
                                    {echo "<div class='off'>OFF [R]</div>";}
                                elseif ($time1['why_off'] == '2') 
                                    {echo "<div class='off'>OFF [ML]</div>";}
                                elseif  ($time1['why_off'] == '0')
                                    {echo "<div class='off'>OFF</div>";}
                            }
                                elseif ($time1['work'] == '0') {
                                    if ($time1['work_type'] == '1') {
                                        if ($time1['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[TL]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[TL]</div>";}
                                    }
                                    elseif ($time1['work_type'] == '2') {
                                        if ($time1['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[SF]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[SF]</div>";}
                                    }
                                    elseif ($time1['work_type'] == '3') {
                                        if ($time1['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[-/+]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[-/+]</div>";}
                                    }
                                    elseif ($time1['work_type'] == '4') {
                                        if ($time1['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close<br>[TR]</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[TR]</div>";}
                                    }
                                    elseif ($time1['work_type'] == '0') {
                                        if ($time1['timeend'] == '23:00:00')
                                        {echo "<div class='working_w'>".$starting." - Close</div>";}
                                            else {echo "<div class='working_w'>".$starting." - ".$ending."</div>";}
                                    }
                                }?>

                </div>
                <?php } ?>

            </td>
            <td class="hoursboth" colspan="2">
            <?php $hour2 = mysql_query("SELECT h.* FROM hours AS h, employees AS e 
                                        WHERE h.s_id = '" .$s_id. "' AND e.u_id = h.u_id AND DATE_ADD((DAYOFWEEK(h.date) = 3), INTERVAL 7 DAY)
                                        ORDER BY e.emp_id ASC");
            while($time2 = mysql_fetch_array($hour2)) { ?>

                <div class="hours">
                    <?php $starting = date("g:ia", strtotime($time2['timestart']));
                        $ending = date("g:ia", strtotime($time2['timeend']));
                            if ($time2['work'] == '1') {
                                if ($time2['why_off'] == '1') 
                                    {echo "<div class='off'>OFF [R]</div>";}
                                elseif ($time2['why_off'] == '2') 
                                    {echo "<div class='off'>OFF [ML]</div>";}
                                elseif  ($time2['why_off'] == '0')
                                    {echo "<div class='off'>OFF</div>";}
                            }
                            elseif ($time2['work'] == '0') {
                                if ($time2['work_type'] == '1') {
                                    if ($time2['timeend'] == '23:00:00')
                                    {echo "<div class='working_w'>".$starting." - Close<br>[TL]</div>";}
                                        else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[TL]</div>";}
                                }
                                elseif ($time2['work_type'] == '2') {
                                    if ($time2['timeend'] == '23:00:00')
                                    {echo "<div class='working_w'>".$starting." - Close<br>[SF]</div>";}
                                        else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[SF]</div>";}
                                }
                                elseif ($time2['work_type'] == '3') {
                                    if ($time2['timeend'] == '23:00:00')
                                    {echo "<div class='working_w'>".$starting." - Close<br>[-/+]</div>";}
                                        else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[-/+]</div>";}
                                }
                                elseif ($time2['work_type'] == '4') {
                                    if ($time2['timeend'] == '23:00:00')
                                    {echo "<div class='working_w'>".$starting." - Close<br>[TR]</div>";}
                                        else {echo "<div class='working_w'>".$starting." - ".$ending."<br>[TR]</div>";}
                                }
                                elseif ($time2['work_type'] == '0') {
                                    if ($time2['timeend'] == '23:00:00')
                                    {echo "<div class='working_w'>".$starting." - Close</div>";}
                                        else {echo "<div class='working_w'>".$starting." - ".$ending."</div>";}
                                }
                            }?>

                </div>
                <?php } ?>

            </td>

助けてくれた人に前もって感謝したいと思います!

4

2 に答える 2

0

水曜日に週を始める方法

0つまり、基本的には、 ~ の範囲の値の範囲を特定の数値だけ「シフト」したいだけです。これは6非常に簡単です。

$shifted_value = ( $actual_value + $offset ) % $number_of_values;

したがって、ここで$offsetは 4 になります (水曜日は PHP の第 3 曜日ですが、 3 を減算すると、モジュロ除算で望ましくない負の値になる可能性があります。そのため、 4を加算することで、過去ではなく「未来へ」をシフトするだけです。[=7-3]) となり$number_of_values、7 になります。

これは PHP バージョンになります。MySQL では同じ方法で実行できます。MySQL では水曜日が週の 2 番目の曜日であるため、オフセットのみを調整する必要があります。

于 2013-05-30T15:49:00.997 に答える