这可能是一个相对简单的PHP脚本,但在尝试了一段时间之后,我很茫然。基于当月的隐藏表格
我有一系列的表(见下文),我想自动隐藏月份已经过去的表。我正在考虑使用PHP来生成嵌入式CSS来实现这一点。我需要一个脚本,基本上做到这一点:
<?php $x=1;
do
{
echo "div.y!CURRENTYEAR!"
echo "$x;,"
$x=$x+1;
}
while ($x < CURRENTMONTH)
?>
我基本上希望脚本写出来:
div.y2013 .jan,div.y2013 .feb,div.y2013 .mar
等等,直到它到达当前月份,这样我就可以隐藏它刚才列出的所有表格。我不确定如何获取数字值并将该数字转换为这个purpsoe的三个字母的月份代码,或者使用各种日期格式代码可以更简单地完成此操作。
我不能真正做的一件事是修改下面的标记。
<div class="y2013">
<table class="month jan">...data...</table>
<table class="month feb">...data...</table>
<table class="month mar">...data...</table>
...
<table class="month dec">...data...</table>
</div>
<div class="y2014">
<table class="month jan">...data...</table>
<table class="month feb">...data...</table>
<table class="month mar">...data...</table>
...
<table class="month dec">...data...</table>
</div>
编辑:
我已经尝试没有成功如下:
<?php
function int2month($int)
{
switch($int)
{
case 1: return "jan";
case 2: return "feb";
case 3: return "mar";
case 4: return "apr";
case 5: return "may";
case 6: return "jun";
case 7: return "jul";
case 8: return "aug";
case 9: return "sep";
case 10: return "oct";
case 11: return "nov";
case 12: return "nov";
default: return "dec";
}
}
$x=1;
do
{
echo "div.y<?php echo date('Y'); ?>
"
echo int2month($x).",";
$x=$x+1;
}
while ($x < date(n))
?>
编辑:终极密码的作品:
<?php
function int2month($int)
{
switch($int)
{
case 1: return "jan";
case 2: return "feb";
case 3: return "mar";
case 4: return "apr";
case 5: return "may";
case 6: return "jun";
case 7: return "jul";
case 8: return "aug";
case 9: return "sep";
case 10: return "oct";
case 11: return "nov";
case 12:
default: return "dec";
}
}
$i = 1;
while ($i < date('m')):
echo "div.y" . date('Y') . " .";
echo int2month($i) . ", ";
$i=$i+1;
endwhile;
echo ".place {display:none!important;}";
?>
这不是因为我改变了它。我做错了什么? –
我试过并在原帖中粘贴了我的结果。有任何想法吗? –
谢谢@Christine,我最终改变了你的代码(而不是一边做的声明,等等)谢谢! –