这是我从在线教程获得的日历脚本。它工作正常,但我想周日的列移动到结束(星期六列后):PHP日历:将星期天的列移动到末尾
<?php
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$month_current = $_REQUEST["month"];
$year_current = $_REQUEST["year"];
$prev_year = $year_current;
$next_year = $year_current;
$month_previous = $month_current-1;
$month_next = $month_current+1;
if ($month_previous == 0)
{
$month_previous = 12;
$prev_year = $year_current - 1;
}
if ($month_next == 13)
{
$month_next = 1;
$next_year = $year_current + 1;
}
$timestamp = mktime(0,0,0,$month_current,1,$year_current);
$lastdate = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$firstday = $thismonth['wday'];
?>
<?php
for ($i=0; $i<($lastdate + $firstday); $i++)
{
if(($i % 7) == 0) echo "<tr>\n";
if($i < $firstday) echo "<td></td>\n";
else echo "<td align='center' valign='middle' height='20px'>". ($i - $firstday + 1) . "</td>\n";
if(($i % 7) == 6) echo "</tr>\n";
}
?>
我试图改变代码到这一点:
<?php
for ($i=0; $i<($lastdate + $firstday); $i++)
{
if(($i % 7) == 1) echo "<tr>\n";
# if $i less than the first day (1), don't print the value of $i
if($i < $firstday) echo "<td></td>\n";
# print the value of $i
else echo "<td align='center' valign='middle' height='20px'>". ($i - $firstday + 1) . "</td>\n";
if(($i % 7) == 0) echo "</tr>\n";
}
?>
然后,它不当第一天从星期天开始时,在列中正确显示。例如:http://ec-ener.eu/dump/index.php?month=8&year=2010
我该如何解决?或者,如何更改原始脚本以便我可以将星期天移动到列的末尾?
p.s.我也刚刚发现,原来的代码似乎有一点问题/错误,如果你检查HTML - TR和TD - 它产生,
<tr>
<td align='center' valign='middle' height='20px'>30</td>
<td align='center' valign='middle' height='20px'>31</td>
</table>
</td>
</tr>
它在闭幕表,只有一个关闭但没有开放。我相信原来的单一简单循环会生成一些无效的html!我可以修复它吗?谢谢!
感谢。它适用于这一行+原始脚本! :-) – laukok 2010-10-03 02:04:16
大声笑我会的!顺便说一句,实际上原来的简单单循环是误导 - 它会产生无效的HTML!你会知道我的意思,如果你阅读我上面发布的编辑问题。谢谢! – laukok 2010-10-03 03:35:55