I have the code <? $i=0; while ($i < 11){ ?> <option value="<? print date('n', strtotime('-1 Month')); ?>"> <? print date('M', strtotime('-1 Month')); ?></option> <? $i++; } ?> Code (markup): i need to chage the print date('n', strtotime('-1 Month')); to not be -1 but be - i how do i do this seeing as i am already within the <? ?> Thanks
worked it out <option value="<? print date('n', strtotime('-'.$i.' Month')); ?>"> <? print date('M', strtotime('-'.$i.' Month')); ?></option>
strtotime('-' . $i . ' Month') You could also compact the whole thing into a for loop: <?php for ( $i = 0; $i < 11; $i++ ) { $time = strtotime('-' . $i . ' Month'); echo '<option value="', date('n',$time), '">', date('M',$time) ,'</option>'; } PHP:
For another variation, this worked for me: $i = 0; while ($i < 11){ print '<option value="' . date('n', strtotime("-$i Month")) . '">' . date('M', strtotime("-$i Month")) . '</option>'; $i++; } PHP: The output went from May to July, with the option value number matching number of the month, in that May==5 and January==1.
I would recommend you to get familiar with Smarty (smarty.php.net). It's a PHP template engine which allows you to separate HTML from PHP completely. It's smarter than you think, so give some and read a little bit of manual. I did some of my sites using it and never looked back to old methods (putting HTML in PHP code)!!!