I have <select>
that displaying year.
I want to check the registered years from the database.
Here's the image.
then here's my code in <select>
<select class="form-control select search-input-select col-lg-9 required_fields yearSelection registered_year" name="registered_year" style="border-color:red;">
<?php
// Sets the top option to be the current year. (IE. the option that is chosen by default).
$currently_selected = date('Y');
// Year to start available options at
$earliest_year = 2018;
// Set your latest year you want in the range, in this case we use PHP to just set it to the current year.
$latest_year = date('Y');
echo '<option style="text-color:red;" selected disabled value>Select Year</option>';
foreach ( range( $latest_year, $earliest_year ) as $i )
{
foreach($year_reg as $year)
{
$reg = date("Y", strtotime($year->date_created));
if($reg == $i){
echo '<option style="color:red;" value="'.$i.'"'.($i === $currently_selected ? ' selected="selected"' : '').' disabled>'.$i.'</option>';
} else {
echo '<option value="'.$i.'"'.($i === $currently_selected ? ' selected="selected"' : '').' >'.$i.'</option>';
}
}
}
?>
</select>
So when the years from database and the earliest - latest years matched, it will become disabled
and color red.
It displays 2019(w/ red text), 2019, 2018, 2018(w/ red text)
now my problem it displays multiple data. What seems to be the problem?