Note that there are some explanatory texts on larger screens.

plurals
  1. POHiding tables based on current month
    primarykey
    data
    text
    <p>This is probably a relatively simple PHP script, but I'm at a loss after trying for a while.</p> <p>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:</p> <pre><code>&lt;?php $x=1; do { echo "div.y!CURRENTYEAR!" echo "$x;," $x=$x+1; } while ($x &lt; CURRENTMONTH) ?&gt; </code></pre> <p>I basically want the script to write out:</p> <p>div.y2013 .jan, div.y2013 .feb, div.y2013 .mar</p> <p>and so on, until it reaches the <em>current month</em>, 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.</p> <p>One thing I can't really do is modify the markup below.</p> <pre><code>&lt;div class="y2013"&gt; &lt;table class="month jan"&gt;...data...&lt;/table&gt; &lt;table class="month feb"&gt;...data...&lt;/table&gt; &lt;table class="month mar"&gt;...data...&lt;/table&gt; ... &lt;table class="month dec"&gt;...data...&lt;/table&gt; &lt;/div&gt; &lt;div class="y2014"&gt; &lt;table class="month jan"&gt;...data...&lt;/table&gt; &lt;table class="month feb"&gt;...data...&lt;/table&gt; &lt;table class="month mar"&gt;...data...&lt;/table&gt; ... &lt;table class="month dec"&gt;...data...&lt;/table&gt; &lt;/div&gt; </code></pre> <p><strong>EDIT:</strong></p> <p>I've tried the following without success:</p> <pre><code>&lt;?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&lt;?php echo date('Y'); ?&gt; " echo int2month($x).","; $x=$x+1; } while ($x &lt; date(n)) ?&gt; </code></pre> <p><strong>EDIT: Final Code that works:</strong></p> <pre><code>&lt;?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 &lt; date('m')): echo "div.y" . date('Y') . " ."; echo int2month($i) . ", "; $i=$i+1; endwhile; echo ".place {display:none!important;}"; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload