我正在制作一个计划脚本,其中一周的开始时间是星期三,结束时间是星期二。我一直在研究并找到如何在星期三开始这一周,但最后一天总是在星期六或星期日结束,取决于使用DAYOFWEEK或WEEKDAY。
我的代码现在正是七天中的每一天......
<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>
我想提前感谢任何人给予的任何帮助!
答案 0 :(得分:0)
如果从日期开始减去某些天并选择产生的一周呢?
SELECT h.* FROM hours AS h, employees AS e
WHERE h.s_id = '" .$s_id. "' AND e.u_id = h.u_id AND
WEEK(DATE_ADD(h.date, INTERVAL -3 DAY)) = 4
ORDER BY h.date, e.emp_id ASC
答案 1 :(得分: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周的第2天。