showing current and next 5 months in combo box

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ranjitbd
Forum Newbie
Posts: 24
Joined: Sun May 03, 2009 1:59 pm

showing current and next 5 months in combo box

Post by ranjitbd »

Code: Select all

 
// i want to show dynamically 6 months including current month in a combo box.
// like when October will be over combo box will show November to April.
// please help me..code can be in php or javascript....
 
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: showing current and next 5 months in combo box

Post by Mark Baker »

This logic may help:

Code: Select all

 
$month = mktime();
 
echo date('M',$month).'<br />';
for($i = 0; $i < 5; $i++) {
    $month = strtotime(date('d-M-Y',$month).' + 1 Month');
    echo date('M',$month).'<br />';
}
 
ranjitbd
Forum Newbie
Posts: 24
Joined: Sun May 03, 2009 1:59 pm

Re: showing current and next 5 months in combo box

Post by ranjitbd »

Mark Baker wrote:This logic may help:

Code: Select all

 
$month = mktime();
 
echo date('M',$month).'<br />';
for($i = 0; $i < 5; $i++) {
    $month = strtotime(date('d-M-Y',$month).' + 1 Month');
    echo date('M',$month).'<br />';
}
 

Code: Select all

 
// your code is nice but i have to implement within a combo box
// so what to do?
<select name="month" id="month">
// any condition for showing six month
            <?php for($i=1; $i<=6; $i++){?>
              <option value="<?php echo $i;?>"><?php echo $i;?></option>
              <?php } ?>
        </select>
 
Post Reply