here is my sample code to display a select box.
But the Month of Feb is always missing from the options list.
being new to PHP, will also appricate to suggest how may I i improve this code.
$birth_month = strtotime("-{$age} Years");
$birthday = strftime("%m.%Y", $birthday_timestamp);
for ($month_itr = 1; $month_itr <= $bis; month_itr++) {
$option_value = strftime("%m.%Y", $birth_month );
$option_text = strftime("%b. %y", $birth_month );
$selected = ($birthday == $option_value ? 'selected="selected"' : '');
echo "<option value='{$option_value}' {$selected}>{$option_text}</option>\n";
$birth_month = strtotime("+1 Month", $birth_month);
}
This line is calculating a date relative to today. As today is the 30th, the date will be the 30th of the relevant month. Given that you are scrolling through the months using “+1 Month” from this date you will always be looking at the 30th of each month. As 30th Feb doesn’t exist, PHP calculates this as 2nd March (i.e. 2 days after 28th Feb). If you use something like
You should be OK.