This is probably a relatively simple PHP script, but I'm at a loss after trying for a while.
I have a series of tables (see below), and I want to automatically hide the tables where the month has already passed. I'm thinking of using PHP to generate embedded CSS to achieve this. I would need a script that basically does this:
<?php $x=1;
do
{
echo "div.y!CURRENTYEAR!"
echo "$x;,"
$x=$x+1;
}
while ($x < CURRENTMONTH)
?>
I basically want the script to write out:
div.y2013 .jan, div.y2013 .feb, div.y2013 .mar
and so on, until it reaches the current month, so that I can then hide all the tables it just listed. I'm unsure how to take a numerical value and convert that number into a three-letter month code for this purpsoe, or maybe there's a much easier way of doing this using the various date format codes.
One thing I can't really do is modify the markup below.
<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>
EDIT:
I've tried the following without success:
<?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))
?>
EDIT: Final Code that works:
<?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;}";
?>
How about an easy function?
<?php
function int2month($int)
{
switch($int)
{
case 1: return "jan";
//.......
case 11: return "nov";
case 12:
default: return "dec";
}
}
$x=1;
do
{
echo "div.y!CURRENTYEAR!"
echo int2month($x).",";
$x=$x+1;
}
while ($x < CURRENTMONTH)
?>
I think the best way would be to add a css class for the passed months via. php.
This way you can set display: none;
to the class.
The generated html should look like this:
HTML:
<div class="y2013">
<table class="month jan passed">...data...</table>
<table class="month feb passed">...data...</table>
<table class="month mar passed">...data...</table>
...
<table class="month dec">...data...</table>
</div>
CSS:
.passed {display: none;}
Edit:
Generate the selectors with php, that you get something like this:
.y2012, .y2013 .jan, .y2013 .feb, .y2013 .mar, .... {dispaly: none;}