Reputation: 338
I'm trying to give the selected attribute to the year that is stored in a SESSION ( in the script I posted the date 1990-06-27 is the SESSION I'm talking about ). Everything goes well for $month but when I do the same If statement for $year is not working and I really have no idea why.
list($y,$m,$d)=explode('-', "1990-06-27");
for($month=1; $month<=12; $month++) {
$monthName = date("F", mktime(0, 0, 0, $month));
$month = date("m", mktime(0, 0, 0, $month));
$luni = array ('January' => 'Ianuarie', 'February' => 'Februarie', 'March' => 'Martie', 'April' => 'Aprilie', 'May' => 'Mai', 'June' => 'Iunie', 'July' => 'Iulie', 'August' => 'August', 'September' => 'Septembrie', 'October' => 'Octombrie', 'November' => 'Noiembrie', 'December' => 'Decembrie');
If($m === $month) {
$selected = 'selected="selected"';
$monthOptions .= "<option value=\"{$month}\" $selected>{$luni[$monthName]}</option>\n";
} else {
$monthOptions .= "<option value=\"{$month}\">{$luni[$monthName]}</option>\n";
}
}
$an_curent = date("Y", time());
for($year = $an_curent - 80; $year <= $an_curent - 16; $year++) {
If($y === $year) {
$selected = 'selected="selected"';
$yearOptions .= "<option value=\"{$year}\" $selected>{$year}</option>\n";
} else {
$yearOptions .= "<option value=\"{$year}\">{$year}</option>\n";
}
}
Upvotes: 0
Views: 104
Reputation: 10840
$year
is an integer, whereas $y
is a string.
Therefore, the ===
operator always returns false.
Using ==
should fix this.
Upvotes: 2