我正在编写一个日程安排脚本,其中一周的开始是星期三,结束是星期二。我一直在研究如何在星期三开始一周,但最后一天总是在星期六或星期日结束,具体取决于使用 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>
我要提前感谢任何人提供的任何帮助!